Problems instantiating a prefab (javascript)

Hello, I’m new to using javascript and I am having some trouble.

In my assets folder, I have a prefab named “enemyprefab”, and I am trying to make a script so a copy of the prefab will spawn at the location of the object I have attatched the script to. Looking at the Unity manuals on the instantiate command and its discussion of instantiating prefabs, led me to believe that this code:

#pragma strict
var enemyprefab : Transform;
function Start () {


Instantiate(enemyprefab, Vector3 (x, y, 0), Quaternion.identity);

}

function Update () {

}

would give me the result I need, but unfortunately it doesn’t work at all. I’ve looked at other questions on this website about this topic, but I just can’t figure out what to do.

Any help is appreciated.

  1. Why are you using 3 floats and not just Vector3().

  2. In your question you said you wanted it to spawn where the script object is located, use this.

    #pragma strict
    var enemyprefab : Transform;
    var clonedObject : Transform;
    var relativePositionOffset : Vector3 = Vector3(0,0,0);
     
    function Start () {
     
     
    clonedObject = Instantiate(enemyprefab, transform.position + relativePositionOffset, Quaternion.identity);
     
    }
     
    function Update () {
     
    }
    

If this doesn’t work then I don’t know what you are doing wrong. This DOES work.