- Home /
Question by
csorkin09 · Nov 25, 2014 at 09:51 AM ·
raycastraycastinginput.mousepositioninput.getmousebuttondown
Raycast calling both if and else statments
When i click on a gameobject in the first position of the list i should get points and remove the object from the list. If i click on a gameobject that is not in the first position in the list then it should be game over. But both the if and else are getting called at the same time. Why is this happening??? This is what i am doing:
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
if (Input.GetMouseButtonDown (0))
{
if(hit.collider.gameObject == list.playerButtons[0])
{
list.playerButtons.Remove(list.playerButtons[0]);
//Debug.Log (hit.collider.);
gameController.AddScore ();
Debug.Log("successfully");
}
else
{
gameOver = true;
if(gameOver == true)
{
Debug.Log("failed");
//Application.LoadLevel("Game Over");
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to stop Input.GetKey from cancelling mouse raycasting? 0 Answers
How do I make raycast ignore the players collider 1 Answer
Raycast not hitting instantiated object when timescale is 0 1 Answer
Rigidbody.position causes shaking 1 Answer
Pushing away rigidbody from the direction of raycast hit 1 Answer