- Home /
Make Raycast that ignores certain tags?
I'm trying to make a raycast that ignores the 'button' tag. I've tried this:
function Update () {
if(Input.GetMouseButtonDown(0)){
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Physics.Raycast(ray,hit,1000))
{
if(hit.transform.tag == "Button"){
Debug.Log("Button");
}else if(hit.transform.tag == "Untagged"){
Debug.Log("Not");
}
}
}
}
Whenever I run the above script it will either stay tagged as a button or not a button whenever I change the tag of the object mid-runtime. How would I make a raycast that ignores a tag?
Put your buttons on a separate layer, then when raycasting ignore that layer with Layer$$anonymous$$ask.
I don't see what te problem is. It just compares two strings (?)
The "else if" loop is useless if you want the collision to be ignored.
I recommend using transform.CompareTag(string tag) ins$$anonymous$$d of transform.tag
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Raycast Destroys player. 1 Answer
Rotation(Y) and Acceleration Camera 0 Answers