- Home /
Trouble Making Trigger From Scratch
Apologies for the basic nature of the question, but I'm having no luck following other solutions/tutorials. What I'm trying to do is set up a very basic trigger completely from scratch. I've done the following, but no dice. What am I missing?
I Create a new scene with a ground plane and two cubes.
Cube #1 is my "player" and gets a basic movement script.
Cube #1 is also given a rigidBody component
Cube #2 is my Trigger. I set "isTrigger" true within its boxCollider
I put the following code onto Cube #2. But at run, nothing fires.
function OnDrawGizmos() {
// Draw a transparent triggerbox for in-editor convenience Gizmos.color = Color.yellow; Gizmos.color.a = 0.5; Gizmos.DrawCube (transform.position, transform.localScale); } function onTriggerEnter(collision : Collider) { Debug.Log("Trigger has been hit by " + collision); } function onColliderEnter(other : Collider) { Debug.Log("Trigger has been hit by " + other); } function Start () { } function Update () { print("FML"); }
I've tried putting the same set of functions on the player script, made sure triggers work in example projects I've downloaded, and verified that a print or Debug.Log actually writes to the console (as in the FML example here) - but cannot for the life of me figure out what I'm missing when it comes to setting up a verrrrry basic trigger from scratch.
Help! I feel like once I understand whatever I'm missing here, I'll be off to the races.
Oh man, I can't believe it was something that simple. Thanks - my usual scripting environment isn't case-sensitive, so I'm still getting used to looking for that. Thanks - I was really pulling my hair out thinking I misunderstood something fundamental.
Can you mark as answered please. What is your normal scripting env?
Thanks, didn't see at first how to mark as answered. $$anonymous$$y usual language is proprietary for the tool I use at work.
Answer by hijinxbassist · Mar 19, 2012 at 10:04 AM
Found it! You functions are named incorrectly
function OnTriggerEnter(collision : Collider) {
Debug.Log("Trigger has been hit by " + collision);
}
function OnColliderEnter(other : Collider) {
Debug.Log("Trigger has been hit by " + other);
}
Notice the capital "O" in OnTriggerEnter and Collider functions. Youre off to the races my friend!
Btw, i like your use of debug tools. Too many people forget to debug or do not know its there. I didnt know about this use of gizmos, im gonna add this to my debug arsenal