Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

Finding name of gameobject that entered a trigger

$
0
0
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(); } }

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>