- Home /
How do I track an object of a specific type at collision?
Hi!
I have been looking around for this answer and can't seem to find it. What I want to do is keep track of a specific object when it hits a trigger of another object. As in, if I have a FPS Controller and it breaks trigger_1, I want to hold gameobject trigger_1, inside of the collision script (on the FPS controller) so that I can manipulate some variable inside the trigger. I would also like to do it vice-versa if possible. Here is an example:
public PositionNode myPosition; //declared earlier
void OnTriggerEnter (Collider other)
{
if(other.gameObject.tag == "Position Node")
{
Debug.Log("I am Touching a Node");
myPosition = other.gameObject;
}
}
This is just a rough example. I know that myPosition is a PositionNode and I don't know how to make sure that the script knows that the other's gameobject is a PositionNode as well.
Thanks for you help in advance!
-Charlie
Your answer
Follow this Question
Related Questions
Collider2D.GetContacts() always returns only 1 contact 1 Answer
How can I access a variable from another script in a separate object? 1 Answer
Change gameObject of the VAR TARGET HELP!!! 1 Answer
how to make a script when u collide with an object it disappears 3 Answers
If two of the same objects spawn on top of each other, is it possible to destroy only one? 0 Answers