Ive been working on refactoring my player stat creation script, i originally had loads of void() and to many public texts and buttons., ive managed to get the buttons to come up. But im unable to work out how to get the buttons and text that i have instantiated in the code to show the stats the player will adjust onto the text.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StatHelp : MonoBehaviour {
public GameObject prefabUpButton, prefabDownButton;
public Text prefabText;
public RectTransform upPanel, DownPanel, textPanel;
private List<int> buttonNumber, buttonDown;
private List<int> stats;
int min = 4, max = 20, startingStats = 8, points = 27;
int tempUp, tempDown, currentStat;
int idea0U, idea0D; // Temporary to try and adjust stats[]
//int Str = 8, Dex = 8,Con = 8,Int=8,Wis=8,Cha=8;
static int upButton = 6, downButton = 6, statTexts = 6;
void Start()
{
buttonNumber = new List<int>();
buttonDown = new List<int>();
stats = new List<int>();
// This creates UpButton
for (int x = 0; x < upButton; x++)
{
GameObject btnUp = (GameObject)Instantiate(prefabUpButton);
btnUp.transform.SetParent(upPanel, false);
btnUp.transform.localScale = new Vector3(1, 1, 1);
Button upBtn = btnUp.GetComponent<Button>();
buttonNumber.Add(x);
int tempUp = x;
upBtn.onClick.AddListener(() => UpClicked(buttonNumber[tempUp]));
}
//This creates a down button
for (int x = 0; x < downButton; x++)
{
GameObject btnDown = (GameObject)Instantiate(prefabDownButton);
btnDown.transform.SetParent(DownPanel, false);
btnDown.transform.localScale = new Vector3(1, 1, 1);
Button downBtn = btnDown.GetComponent<Button>();
buttonDown.Add(x);
int tempDown = x;
downBtn.onClick.AddListener(() => DownClicked(buttonDown[tempDown]));
}
//This creates statTexts
for (int t = 0; t < statTexts; t++)
{
Text text = (Text)Instantiate(prefabText);
text.transform.SetParent(textPanel, false);
text.transform.localScale = new Vector3(1, 1, 1);
int tempText = t;
stats.Add(t);
}
}
void UpClicked(int UpBtnNo)
{
Debug.Log(" Up Button Clicked = " + UpBtnNo);
}
void DownClicked(int DownBtnNo)
{
Debug.Log("Down Button Clicked = " + DownBtnNo);
}
}
Everything is currently going in to lists.
how am i able to put text into the instantiated text, that wont change all of the text boxes created?
or is there a much better way of doing so which i haven’t thought of?