I am having a bit of trouble adding items to a scroll view dynamically.
Say the user has a deck of cards, holding 5 cards in his deck out of a possible 30 in the entire game. How would I add the 5 cards to the Scroll View? The cards are made from a prefab using two planes (Front and Back).
I have set up my Scroll View based on this video I found:
https://www.youtube.com/watch?v=AjzJrbiTJgE up to the point where he creates the RootGrid and ItemPref GameObjects. I am assuming the RootGrid should be my UIGrid and the ItemPref should be my Card prefab.
The Card class looks like this:
public class Card : MonoBehaviour {
//Holds all textures for every card so when instantiated can set individual card texture itself
public Texture[] texArray;
public Texture backTexture;
public GameObject face;
public GameObject back;
//Holds each cards GameObject for use when moving it
public GameObject cardObject;
//Variables to hold values
public int topValue;
public int bottomValue;
public int leftValue;
public int rightValue;
public int id;
public int deckIdentifier;
//Called when a Card instance is made, sets the texture of the card to the id
void Start()
{
//Set the face of the card to the texture in array based on the cards id (Set when instantiating)
face.renderer.material.mainTexture = texArray[id];
//Set the back of the card to backTexture (Same for every card)
back.renderer.material.mainTexture = backTexture;
}
int GetTopValue()
{
return topValue;
}
int GetBottomValue()
{
return bottomValue;
}
int GetRightValue()
{
return rightValue;
}
int GetLeftValue()
{
return leftValue;
}
}
I tried the following code and found that the grid was not in its correct place on the panel, instead way off the screen.
using UnityEngine;
using System.Collections;
public class ScrollView : MonoBehaviour {
public GameObject RootGrid;
public GameObject Card;
public GameObject panel;
// Use this for initialization
void Start () {
for (int i = 0; i < Player.playerDeck.getLength(); i++)
{
Card = Player.playerDeck.getCard(i).gameObject;
NGUITools.AddChild(RootGrid, Card);
Card.transform.parent = RootGrid.transform;
RootGrid.GetComponent<UIGrid>().Reposition();
}
}
}

I feel like I'm doing this completely wrong but because I've been following a Russian video I don't fully understand if this is the correct way, any help would be appreciated.