Why does this tutorial make a new object.

Can someone tell me why this Java script from this tutorial makes a new object:

var thePrefab : GameObject;

function Start () {

var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);

}

I am Just learning Java script. I already know a litle C++ so I might be treating some code like C++, so just holler and tell me how to do it in Java.

Here are the things I do not understand about this script:

  1. What exactly is the command Instantiate
  2. Why Does setting the variable instance to Instantiate, run the command Instantiate. I would think it would set the value of instance to the text of the Instantiate command. So I could say some thing like "print var instance and it would show on screen, Instantiate(thePrefab, transform.position, transform.rotation)".
  3. I tried running the script with out setting the variable instance to Instantiate and it still made a new object, why then set variable instance to the instantiate command? I used the code:

var thePrefab : GameObject;

function Start() {

Instantiate(thePrefab, transform.position, transform.rotation);

}

  1. Read the docs on Instantiate. It creates an instance of an object in the scene.
  2. I'm not sure what you mean by "the text of the Instantiate command". `instance` is a variable `Instantiate` is a function call which returns a value - this is pretty standard programming regardless of the language. If you wanted to store the string "Instantiate(thePrefab, transform.position, transform.rotation)", you would escape it with quotes like I just did.
  3. `Instantiate` returns the object. Assigning `instance` to the returned object is so that you have the instance of the object in the scene to act upon. You don't have to do anything with the returned value so you can easily call the function without assigning its return value to anything.