Ive been searching for over an hour now guys, and i cant seem to figure out how to simply destroy a rigidbody (the bullet) and replace it with a gameObject (the bullet hole decal). I got this much code done and attached it to my bullet:
var destroyTime = 2.0;
var Decal = Transform;
function Update () {
Destroy(gameObject, destroyTime);
}
function OnCollisionEnter(collision : Collision) {
Destroy(gameObject);
Instantiate (Decal);
}
But it keeps giving me an error on the Instantiate part: Assets/BulletDespawn.js(13,21): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(System.Type)’ was found.
…Any help would be greatly appreciated!
Instantiate requires an object to create… a position to create it in… and a rotation… so yeah you’re instantiate call is a bit wrong. Set bullet hole position to the bullet’s hit position and rotation to the hit point normal+world up vector.
http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html
There’s a lot wrong.
Line 2 declares Decal as the Type Transform not an instance of a Transform. (Which is why you’re getting an error in the Instantiate). Use a colon instead of an equals sign and assign it via Inspector
Don’t call Destroy in Update because it’ll call that every frame. Just put it in Start or Awake.
Note: There is an overload of Instantiate that takes a single argument. It places the resulting object at world origin with default rotation.