0

I am using Physics (Physics.Raycast(ray, out hit)) in Unity

when I touch the screen I add a sphere at the point of collision,

also, I have a button to remove the last sphere inside the scene,

but I have this problem (when I touch the screen on that button) a new sphere added and deleted at the same time .. how to disable the Raycast from hitting the scene while I am hitting the button ??

1 Answers1

0

The RaycastHit object give you a lot of information about what it hit. You can use that information to decide whether you wanna spawn a sphere or not.

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

if (Physics.Raycast(ray, out hit, 100))
{
    if (hit.transform.name != "myButtonName")
    {
        //spawn sphere
    }
    else
    {
        //remove last sphere
    }
}
Behnam Rasooli
  • 712
  • 5
  • 20
  • actually i am using the onGui() method to add the button inside the UI , HOW can i get it's name property –  Jul 03 '18 at 14:16