Hi!
I’m new working with Unity, and i need to know how i can destroy a cube if i touch over this. For example i need to destroy only the cube B if i touch over this. PD I working with augmmented reality.
I hope that you can help me!
Hi!
I’m new working with Unity, and i need to know how i can destroy a cube if i touch over this. For example i need to destroy only the cube B if i touch over this. PD I working with augmmented reality.
I hope that you can help me!
I created a script with this code and attached it to my Main Camera. It seemed to work.
void Update () {
if (Input.GetMouseButtonDown(0))
{
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Destroy(hit.collider.gameObject);
}
}
}
You can modify it from here to suit your needs. Let me know how it will go.