Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Please help me with Instantiate! [SOLVED]

Discussion in 'Scripting' started by LightWell, Sep 7, 2014.

  1. LightWell

    LightWell

    Joined:
    Sep 6, 2014
    Posts:
    43
    Hey guys, I recently transitioned from GameMaker to Unity and let me tell you, not smooth at all. So, basically here:
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. public var bb = GameObject.Find("bb");
    4.  
    5. public var wc = GameObject.Find("wc");
    6.  
    7. function Start () {
    8. print("Is this the main thread?");
    9.  
    10.  
    11. }
    12.  
    13. function Update () {
    14. if(Input.GetMouseButtonDown(0)) {
    15.         var bbClone = Instantiate(bb, Vector3 (Input.mousePosition.x, Input.mousePosition.y, 3), transform.rotation);
    16.  
    17. }
    18. }
    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.
     
  2. Jamcount

    Jamcount

    Joined:
    Apr 20, 2014
    Posts:
    44
    Code (JavaScript):
    1. #pragma strict
    2. var bb : GameObject;
    3. var wc : GameObject;
    4. function Start () {
    5. print("Is this the main thread? I guess");
    6. bb = GameObject.Find("bb");
    7. wc = GameObject.Find("wc");
    8. }
    9. function Update () {
    10. if(Input.GetMouseButtonDown(0)) {
    11.         var bbClone = Instantiate(bb, Vector3 (Input.mousePosition.x, Input.mousePosition.y, 3), transform.rotation);
    12. }
    13. }
    I think that is the proper way of doing it, but i am not entirely sure.

    -Jamcount;
     
  3. LightWell

    LightWell

    Joined:
    Sep 6, 2014
    Posts:
    43
    Thanks for the help!
    Thank you so much!
     
    Jamcount likes this.
  4. Jamcount

    Jamcount

    Joined:
    Apr 20, 2014
    Posts:
    44
    No problem, i am glad i could help.

    -Jamcount;