I have a simple AR app in unity for android. A 3d model(fox) is generated when the camera track an image. It works fine.
I want to tap the 3d model from android phone and open a second scene.I can do with a button but I can't use the 3dmodel as button. Is there a way to use a 3d model as button? thanks
I finally use Raycast and I make 6 3dmodels. I put mesh collider on all of them an I use a switch to open the correspond scene. here is the code of one of the models. It works fine with mouse click and also in android screen tap. Many thanks to Stitt
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System;
public class GoToScene : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButton(0))
{
Vector3 mousePosFar = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.farClipPlane);
Vector3 mousePosNear = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane);
Vector3 mousePosF = Camera.main.ScreenToWorldPoint(mousePosFar);
Vector3 mousePosN = Camera.main.ScreenToWorldPoint(mousePosNear);
RaycastHit hit;
if (Physics.Raycast(mousePosN, mousePosF - mousePosN, out hit))
{
var tagGit = hit.transform.gameObject.tag;
if (int.TryParse(tagGit, out int caseSwitch))
{ caseSwitch = Int32.Parse(tagGit); }
else { }
switch (caseSwitch)
{
case 1:
SceneManager.LoadScene("FoxScene");
break;
case 2:
SceneManager.LoadScene("TigerScene");
break;
case 3:
SceneManager.LoadScene("RaptorScene");
break;
case 4:
SceneManager.LoadScene("PenguinScene");
break;
case 5:
SceneManager.LoadScene("BeeScene");
break;
case 6:
SceneManager.LoadScene("EagleScene");
break;
default:
break;
}
}
}
}
}