- Home /
OnTriggerEnter(hit : Collider) and (other : Collider)
Besides having to put hit.gameobject.tag or other.gameobject.tag in an if statement, is there any difference between these two things? Will either work just fine or is it two completely different scripts with there own set function? And if so, would I be able to just make two OnTriggerEnter functions with either collider call?
Answer by Jesse Anders · Apr 17, 2011 at 04:55 AM
That depends on the context. I assume you're referring to checking the tag of an object returned by a raycast as opposed to checking the tag of an object in a collision callback; if so, those are indeed two different things (although the 'checking the tag' part is the same).
If there's something in particular you're wondering about, perhaps you could post some example code along with a specific question about that code.
well, i haven't even worked with raycasts yet, so it was simply just detecting an object collision. The main reason I was asking, was because I was exactly able to test the code out until I figured out a different problem, which is now solved, and yea, for what I was doing, they act as the same. Thanks for the response
I think you misunderstood the question, Jesse :) If I understood correctly, Paige wondered why in all available examples the code either said OnTriggerEnter(hit:Collider) or OnTriggerEnter(Other:Collider).
Hehe, in order to mis-understand the question, I would've had to have understood it in the first place, which I didn't :) As such, my answer was just a 'best guess', more or less.
Answer by Joshua · Apr 18, 2011 at 02:33 AM
You're using the function OnTriggerEnter. This function requires a variable: what entered the trigger? You're asking this question while calling this function, and giving the 'what' (which will be a collider, therefor the ': Collider' part) a name. You could call it hit, which is logical when raycasting: it's the object your ray hits, or you could call it bumperdibumpididoo which would make sense if you're checking if something hit's your gameObject and you're insane.
So what you're confused about is that hit and other aren't commands, they are names you're giving to a to-be-assigned collider which will enter your trigger.
see, i was wondering if thats what it truly was, so its basically like a variable thats being named. that makes a lot of sense. thanks