Hey guys facing a strange issue.While detecting the click on gameobjects using Raycasting,sometimes the code gets executed multiple times. Here is the code
void Update ()
{
if (Input.GetMouseButton(0))
{
Ray ray;
RaycastHit raycast;
ray=Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out raycast))
{
switch( raycast.collider.name)
{
case "First_Sphere":
GameObject go = (GameObject)Instantiate(Resources.Load("1ValenceBondElementPrefab"),new Vector3(0,0,0),Quaternion.identity);
break;
}
}
}
}
What leads to this multiple calling and why sometimes it leads to multiple calls and sometimes it is executed properly