- Home /
Instantiate Code Issue
Lads, I'm trying to instantiate an explosion but keep having problems. Here's the code:
var explosionPrefab: Transform;
function OnCollisionEnter(collision : Collider) { if (collision.gameObject.tag == "missile_1") { Instantiate (explosionPrefab, transform.position, transform.rotation, 3); } }
Any thoughts?...
Stef
At a glance the code looks ok, so some indication of how it is failing would be helpful. Is there an error message, or is it just not working?
The prefab is not in a resources folder, should it be? Here's the current error: Script error: OnCollisionEnter This message parameter has to be of type: Collision The message will be ignored.
Things you want to instantiate have to be in a Resources folder. The error seems to be that you have to use Collision in the function parameter and not Collider.
function OnCollisionEnter(col : Collision){...}
You can make in one of 2 ways: Coroutine, or Invoke. http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html
Your answer
Follow this Question
Related Questions
Instantiate as child 3 Answers
Code Optimization Question 1 Answer
This segment of code is causing problems 2 Answers
Passing variables to an instantiated object 1 Answer
How to detect empty slot and spawn gameobject there? 1 Answer