- Home /
Selecting and deselecting not working
void selection()
{
ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(ray2,out hit2,100))
{
if(hit2.transform.tag == "Player")
{
selected = true;
} else{
selected = false;
}
}
}
}
For some reason i can't get this code to work, anyone have any ideas what i did wrong. There is no errors, and i have declared all the variables correctly.
Comment
Is that function being called in the Update function? Also, make sure you have assigned the player the tag and perhaps increase the distance in case it happens to be farther apart.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Why Does My GameObject Not Spawn Anymore? 2 Answers
A problem with intersection detection 1 Answer
Starting out C# help 2 Answers
Two exact objects behaving differently... *scratches head* 0 Answers