Check who triggered the trigger (3D)
So i was making a online game, i plan to make the players pick their classes in game, not by a ui menu, so it's a trigger, so i want to access the script from the player that triggered the trigger, but how?
Answer by streeetwalker · Mar 24, 2020 at 03:26 PM
@Raxoez, There is a difference in coding tactic between "accessing the script FROM the player" and "accessing the script OF the player." The answer to your question it depends on what you mean.
OnTriggerEnter will fire as long as these are true: the player has a collider and the trigger object has a collider, and one them has a rigid body, and one of the collider components' Is Trigger is set to true.
If all of those conditions are satisfied, OnTriggerEnter will fire on both - it doesn't matter which one has the Is Trigger or the rigidbody. Therefore, as long as you have an OnTriggerEnter in a script attached to one them, that script code will detect the collision (you can put the function in a script on each object and both will fire).
So there is your answer: it depends on your meaning of the term "from." If you interpret it the same way I do, then put OnTriggerEnter in a script attached to the player, and that script will have full access to all of the variables and methods in that "player" script as well as all of the attributes of the "player" object it is attached to.