Search Unity

Won't instantiate?!?!?

Discussion in 'Scripting' started by Josenifftodd, Feb 9, 2016.

  1. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    I've been trying to make my card instantiate from a list... but its not working, I'm trying to add it to a canvas and my object is a rect transform. I'm not sure whats going wrong...

    Code (CSharp):
    1.  {
    2.                // Debug.Log("Player has " + player1Hand[i]);
    3.                 Instantiate(player1Hand[i]);
    4.                 player1Hand[i].transform.parent = SpawnPoint.transform;
    5.  
    6.             }
     
  2. Gilmar

    Gilmar

    Joined:
    Dec 17, 2013
    Posts:
    30
    you seem to be changing the reference objects transform instead of the instantiated one

    try this

    Code (csharp):
    1.  
    2. GameObject go = (GameObject)Instantiate(player1Hand[i]);
    3. go.transform.parent = SpawnPoint.transform;
    4.  
     
  3. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Just checked this and seen it, I figured it out straight after I posted. Thanks though! I did this. :)

    Code (csharp):
    1.  
    2. public RectTransform SpawnPoint; // use this to stop yellow error.
    3. GameObject go = (GameObject)Instantiate(player1Hand[i]);
    4. go.transform.SetParent(SpawnPoint.transform);
    5.