- Home /
Detonation of an object on collision of character....
Hiya guys! I pretty much don't know anything about coding and I want to make a very simple one, I'm pretty sure I know what needs to happen but I'm not sure how to present it. I simply want a code for making a rock explode when the character runs into it. Preferably sound and explosion animations included. PLEASE HELP.
Answer by Montraydavis · Oct 29, 2012 at 09:51 AM
The Explosion Framework provided by Unity is simply amazing. Just instantiate the prefab(s) on collision like so:
function OnCollisionEnter ( )
{
if ( collision.collider.tag == "player_tag_name" ){
Instantiate ( Resources.Load("explosion-prefab-name"), transform.position, Quaternion.identity ) ; // Creates / Loads explosion from prefab
GameObject.Destroy ( gameObject ) ; // Kills object
}
}
Obviously though, you need to change the position and rotation to the point of impact. Good luck.
Unity Explosions Framework: http://unity3d.com/support/resources/unity-extensions/explosion-framework
Your answer
Follow this Question
Related Questions
How to make an object explode? 2 Answers
How can i make my scene restart once my character has collided with another object? 2 Answers
Tree collision 1 Answer
Tree collision 1 Answer
Collision with terrain 0 Answers