- Home /
This question was
closed Jun 22, 2017 at 08:35 PM by
GrumblingRose for the following reason:
Managed to figure it out by myself
Question by
GrumblingRose · Jun 23, 2017 at 03:59 AM ·
prefablistsscrollview
Advice on how to reference a list in a scrollview with prefabs
Hi Everyone, I'm trying to learn Unity and have been following some tutorials. For the item shop tutorial, I've managed to follow the tutorial and am thinking of using the system to create a menu that populates buttons based on how many units you have, but I would like to be able to have the menu reference items from a list, instead of typing out the data in the content panel as shown in the tutorial.
Are there any tutorials on doing such a thing? Or what keywords should I be searching for to get some clues to how to achieve this? Any tips on what to look for would be really appreciated, thank you. Tutorial code attached below:
public class UnitMenuScrollListScript : MonoBehaviour {
public List<UnitStats> UnitMenuList;
public Transform contentPanel;
public UnitObjectPoolScript UnitObjectPool;
// Use this for initialization
void Start ()
{
RefreshDisplay ();
}
void RefreshDisplay()
{
AddUnitMenuButton ();
}
private void AddUnitMenuButton()
{
for (int i = 0; i < UnitMenuList.Count; i++)
{
UnitStats Unitstat = UnitMenuList[i];
GameObject newButton = UnitObjectPool.GetObject();
newButton.transform.SetParent(contentPanel, false);
UnitMenuButtonScript sampleButton = newButton.GetComponent<UnitMenuButtonScript>();
sampleButton.Setup(Unitstat, this);
}
}
}
Comment