How would I write a code to identify objects that enter a trigger in Unity3d? (eg. An object named, "Cube", enters a trigger. The trigger then displays, "Cube", in the Debug tab.)
Asked
Active
Viewed 679 times
-2
-
1If you copy the title of this question into Google search bar, you will find many solution. Not sure why you didn't do that. – Programmer Jun 06 '18 at 18:31
-
Try this: https://stackoverflow.com/a/42627702/2938526 – Rodrigo Rodrigues Jun 06 '18 at 18:39
-
void OnTriggerEnter(Collider other){ string name = other.gameobject.name;} . Even basic research would have yield an answer to this. – Tyler S. Loeper Jun 06 '18 at 18:59
-
1Possible duplicate of [How to detect an object in a trigger?](https://stackoverflow.com/questions/42627581/how-to-detect-an-object-in-a-trigger) – shanji97 Jun 06 '18 at 19:10
-
Post also the inspector values for the object that is the trigger and the object that should trigger it. The question also has to be migrated to Gamedev SE. – shanji97 Jun 06 '18 at 19:12
1 Answers
0
private void OnTriggerEnter(Collider other)
{
Debug.Log(other.gameObject.name);
}
A simple Google search would likely suffice for this question, but there's the code for it anyway.
That code should be in a Monobehaviour script on the GameObject that is being collided with (E.g, a wall).
More on this here: https://unity3d.com/learn/tutorials/topics/physics/colliders-triggers

Kieran Bond
- 84
- 1
- 8