- Home /
This question was
closed May 07, 2018 at 08:14 AM by
Myth for the following reason:
The question is answered, right answer was accepted
Collision script
How can I send a message to the object, that the object with this script, collided with?
var explosion : GameObject;
function OnCollisionEnter (collision : Collision)
{
// Instantiate explosion
Instantiate (explosion, transform.position, transform.rotation);
// Stop emitting particles in any children
var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter);
if (emitter)
{
emitter.emit = false;
}
// Destroy the probe
Destroy(gameObject);
}
Comment
Best Answer
Answer by Dreamer · May 25, 2011 at 01:48 AM
Inside OnCollisionEnter function, you can use collision variable. It contains the information about the collision happened.
Refer to :http://unity3d.com/support/documentation/ScriptReference/Collision.html
You could easily locate the object collided with by collision.gameObject. Then you can call functions of that object by
collision.gameObject.GetComponent(Script_Name).do_something();