- Home /
how do i make that only triggers a specific object
Answer by Kergal · Feb 06, 2013 at 11:46 PM
I assume your question is : " How can I make sure that an event will only be triggered through a certain GameObject?"
public string tagToCompare = "Player";
void OnTriggerEnter( Collider col ) { if( col.transform.tag == tagToCompare){ DoSomething..... } }
instead of (col.transform.tag.....) you could also use if(col.transform.CompareTag(tagToCompare)) the second solution will be true if the collider object has the specified tag.
Make sure to give your "object" a collider and a tag. Further set tagToCompare equal to the object's tag.
This solution hopefully :) works for C# .
However, here is the link to the API :
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
I hope I could help, best wishes .
Daniel
Your answer
Follow this Question
Related Questions
Having a particle effect stick to player 0 Answers
Find object that enters trigger 1 Answer
Destroy an enemy when it touches an object 2 Answers
End game then an Object is close to another object? 0 Answers
Retrigger animation after play through 0 Answers