Search Unity

spawn each card .1 above each other

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

  1. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    Code (CSharp):
    1. public RectTransform prefabdeck;
    2.     public GameObject spawnSpot;
    3.     public Transform c;
    4.     // Update is called once per frame
    5.     public void OnClicked () {
    6.         Transform deck = Instantiate(prefabdeck[i], spawnSpot.transform.position, Quaternion.identity) as Transform;
    7.         deck.transform.SetParent(c, true); // -- C is Canvas which the card becomes child of
    how would i make each card spawn say .1 above each other so when they are dragged it doesn't move other cards too.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    it's going to be a little tricky to know what other cards exist from a stand alone function like that... you might be able to get the childcount of "c" and work with that. But the basic "how to change the spawn position" would be

    Code (csharp):
    1.  
    2. Transform deck =Instantiate(prefabdeck[i], spawnSpot.transform.position + (Vector3.up * 0.1f), Quaternion.identity)asTransform;
    3.  
     
  3. Josenifftodd

    Josenifftodd

    Joined:
    Nov 29, 2013
    Posts:
    158
    That seems to move the position of where it's spawned but it's not making a pile of cards, think it needs to add .1f to each of the cards spawned... not sure how id do that lol. :p