Why doesnt this work?
function OnCollisionEnter(hit: Collision){
if(hit.gameObject.tag == "Collectable"){
print("hit collectable");
}
}
Why doesnt this work?
function OnCollisionEnter(hit: Collision){
if(hit.gameObject.tag == "Collectable"){
print("hit collectable");
}
}
Put a print statement outside the if block. Maybe something like:
print(“OnCollisionEnter was called. Tag was”+hit.gameObject.tag);
Then you will be able to confirm if the function was called in the first place and what game object tag is there.
You didn’t exactly say what didn’t work … but I will presume that you aren’t seeing output from “hit collectable” (the print statement).
There are a number of possible reasons that the print statement is not being reached: