- Home /
Destroying upon collision
Im new can someone lend a helping me understand this script.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Transform explosionPrefab;
void OnCollisionEnter(Collision collision) {
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate(explosionPrefab, pos, rot) as Transform;
Destroy(gameObject);
}
}
If you want help with code please format it correctly by using the 101/010 button.
Sorry somehow the script didn't paste completely and I didn't notice
Answer by Jeff-Kesselman · Jan 14, 2015 at 07:19 PM
Itrs pretty clear from this code you have no idea how collision works.
Read this: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.html
If you still don't understand consider doing a tutorial or reading the GOldstone book.
Your answer
Follow this Question
Related Questions
Destroy on collision wont work with mesh collider 1 Answer
expecting (, found 'OnGui' HELP!!! 1 Answer
Destroying multiple objects sometimes destroys more or less 1 Answer
Destroy script turns objects into ghosts 2 Answers
Character Clipping Through Walls When Uncrouching and Receiving Errors 2 Answers