Finding name of gameobject that entered a trigger
I'm trying to create a script that has a game object follow another game object that enters the collider. In order to do so, I've tried referring to the object that entered the trigger as other.gameObject, so I can get its transform component, but the Unity doesn't understand what I'm trying to do.
In short, I'm trying to get the component of a game object that enters a trigger without having to refer to its name. Is it possible to do this, or is it that I just haven't found how to do this?
Thanks.
Here's what I have so far: Initialized variables: private bool playerDetected = false; private GameObject Target;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "PlayerCharacter")
{
playerDetected = true;
Target = other.gameObject.GetComponent<Transform>();
}
}
Your answer
Follow this Question
Related Questions
Trigger Collider is Triggering? 0 Answers
Trigger enter and directly Exit 0 Answers
Trigger issues 1 Answer
Triggers colliding with triggers 1 Answer