Simple Instantiate/Spawning Example

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.

um am I missing something?

OnCollisionEnter passes a collision, not a collider, try changing

function OnCollisionEnter (collision : Collider) {

to

function OnCollisionEnter (collision : Collision) {

Also, in your instantiate, you have to provide more details. Check out the overview on it here: http://unity3d.com/support/documentation/ScriptReference/index.Instantiate.html

The Instantiate function needs 3 variables:

  1. What object you want to Instantiate.
  2. Where it needs to be Instantiated.
  3. The rotation of the Instantiated object.

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);
    }
}

As the error says, you need to use Collision for the type (and not Collider). By the way, it’s better to use CompareTag:

if (collision.CompareTag ("Player")) {