- Home /
Question by
Wakeful · Jul 17, 2014 at 07:40 AM ·
c#2dgetcomponentontriggerenterother
Is there a way to find other's components using OnTriggerEnter?
Can I make a script when a game object gets triggered by another game object and it checks if it has a certain Variable and what that Variable it? Basically checking if other has that certain value. So if another object it touches has different variables it would use those ones and change the variables depending on what object it touched.
Example:
void OnTriggerEnter2D(Collider2D other) {
if(other.Alive == true)
Attack();
}
Im not sure who to get that component into the equation... If anyone can help that would be great! Thx
Comment
Best Answer
Answer by HarshadK · Jul 17, 2014 at 07:42 AM
Simple:
void OnTriggerEnter2D(Collider2D other) {
if(other.gameObject.GetComponent<YourComponentName>().Alive == true)
Attack();
}
Your answer
Follow this Question
Related Questions
AI Attack Not Working! W/Video 1 Answer
how to use bool from another script in if statment? 2 Answers
C# - Problem with trigger that won't activate 1 Answer
GetComponent giving error 3 Answers
OnTriggerEnter2D with multiple objects 0 Answers