I am using the Kudan
plugin in Unity
for building an android app. I am using the markerless mode. When I tap (touch) model, which spawns in this markerless mode, I want to destroy it. I am using a Raycast
script as listed below. I tried attaching the script to Kudan
Camera. Also I created a public Camera gameobject and passed the Kudan Camera to it. However neither option works.
Does anyone know what I am doing wrong?
public Gamobject model;
if (Input.touchCount > 0)
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);
if (Physics.Raycast (ray, out hit))
{
if (hit.collider.gameObject.tag == "chair")
{
Destroy (model);
}
}
}
Thanks in advance!
Assuming that your actual code is correct and says GameObject instead of Gamobject and your if statement has an opening brace, etc, it could be that:
But really, an easier and probably better method would be to not use a Raycast at all. If you make a method in a script:
void OnMouseDown
{
Destroy(gameObject);
}
and attach that script to your model, then when the user clicks on the model (or taps on mobile), provided it has a collider, it will be destroyed.