Please help me with Instantiate! [SOLVED]

Hey guys, I recently transitioned from GameMaker to Unity and let me tell you, not smooth at all. So, basically here:

#pragma strict

public var bb = GameObject.Find("bb");

public var wc = GameObject.Find("wc");

function Start () {
print("Is this the main thread?");


}

function Update () {
if(Input.GetMouseButtonDown(0)) {
        var bbClone = Instantiate(bb, Vector3 (Input.mousePosition.x, Input.mousePosition.y, 3), transform.rotation);
 
}
}

So, this doesn’t exactly “work” so to say, and it returns with: Find can only be called on the main thread.
And, when I try to make it a variable in side of function Start, it just tells me it wasn’t made, so I thought that’d I would have to make it public… well, not the case, so any help would be greatly appreciated!

I found the documentation of this command didn’t really help, and I’ve read through a few forum posts, so can you please walk me through this slowly, I’m not used to JS quite yet, so sorry for being slow in advanced

~ Michael.

#pragma strict
var bb : GameObject;
var wc : GameObject;
function Start () {
print("Is this the main thread? I guess");
bb = GameObject.Find("bb");
wc = GameObject.Find("wc");
}
function Update () {
if(Input.GetMouseButtonDown(0)) {
        var bbClone = Instantiate(bb, Vector3 (Input.mousePosition.x, Input.mousePosition.y, 3), transform.rotation);
}
}

I think that is the proper way of doing it, but i am not entirely sure.

-Jamcount;

Thanks for the help!
Thank you so much!

1 Like

No problem, i am glad i could help.

-Jamcount;