I’m new to Unity3d I’m trying to learn the basics.
Basically I’m trying something simple. When my character collides with a Cube it spawns a rock next to it.
This is my Script.
var Rock : Transform;
function OnCollisionEnter (collision : Collider) {
if(collision.gameObject.tag == "Player"){
Debug.Log("yay");
Instantiate (Rock);
}
}
I have attached this script to the Cube…
I’m getting nothing in the console, nothing is spawning. No errors.
I believe I got this code from one of manual I just change the prefab.
Could someone help me out?
Edit I am getting a error
Script error: OnCollisionEnter
This message parameter has to be of type: Collision
The message will be ignored.
And it needs to be Collision in the OnCollisionEnter field not Collider.
var Rock : Transform;
function OnCollisionEnter (collision : Collision)
{
if(collision.gameObject.tag == "Player")
{
Debug.Log("yay");
Instantiate (Rock, where I want it, what rotation it needs);
}
}