- Home /
Use OnCollision to trigger particle activation
I'm trying to set up a script where upon contact with the player, a crystal will start to emit particles. However, it seems like nothing is happening when they collide. Is there something wrong with this script I wrote?
function OnCollisionEnter( collision : Collision ){
if (collision.gameObject.tag == "Player"){
particleEmitter.enabled = true;
Score.Crystal ++;
}
}
Answer by BoredKoi · Jun 21, 2010 at 06:16 PM
There is nothing "wrong" with the script you wrote. There are, however, obviously issues with the how the Game Objects are interacting when you run your game.
The console print idea is valid enough for debugging within the current Unity iPhone product. I would start with something simpler, however:
function OnCollisionEnter( collision : Collision )
{
print(collision.gameObject.name);
}
If you are seeing no Collision messages, then you are (most likely) missing a Rigidbody for one of the two colliding objects.
Check the matrix at the bottom -- that will tell you how Collision and Trigger messages are generated.
Lastly, once you get past that issue, make sure to disable or otherwise remove print / Debug.Log messages from your final release product. They are unkind to performance.
Answer by AnaRhisT · Jun 20, 2010 at 08:17 PM
arrange ur scripts, be smart, put prints! Does it print on collision?
function OnCollisionEnter( collision : Collision ){
if (collision.gameObject.tag == "Player"){
print("There's a collision");
}
}
This is not so much an answer but a suggested technique for finding the answer.
Exactly. I don't need to feed him with a spoon, but to show him how to eat. people who de-reped me why don't u show ur answers?