Hey Guys,
This is my Scriptable Object:
using UnityEngine;
[CreateAssetMenu(fileName = "New Skill", menuName = "Skill")]
public class Skill : ScriptableObject {
public new string name;
public bool isLearned;
public float damage;
public float cooldown;
public float range;
public Sprite icon;
}
And this is my Script for creating the UI:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkillSelection : MonoBehaviour {
public List<Skill> skill;
public GameObject button;
public List<GameObject> buttonList;
public Text skillText;
public List<Text> skillTextList;
void Start () {
for (int i = 0; i < skill.Count; i++)
{
Instantiate(button, transform);
buttonList.Add(button);
Instantiate(skillText, button.transform);
skillTextList.Add(skillText);
buttonList_.GetComponent<Image>().sprite = skill*.icon;*_
skillTextList_.text = skill*.name;*_
if (skill*.isLearned == false)*
buttonList*.SetActive(false);*
}
}
}
The Script is attached to a Panel in the Scene and 4 Objects of the type Skill + a Button- and Text-Prefab are attached to the Script.
What I want the Script to do:
-Create an instance of the Button-Prefab for each Skill attached (4 in this case)
-Child the Prefab to the Panel so its position gets sorted via the Grid Layout
-Change the Sprite of the Prefab to the corresponding Sprite set in the Skill-Object
-Create a Text with the name of the Skill and Child it to the Button
-Disable the Button if the isLearned Bool is set to false
What the Script currently does:
-Creates 4 Instances of the Button(as a Child of the Panel)
-The Sprites of the Buttons are not in the correct order (4,1,2,3) instead of (1,2,3,4)
-No Text is created for Button 1, 1 for Button 2, 2 for Button 3, and 3 Texts for Button 4
-After 1 playtest, the Prefab itself is disabled, not allowing me to do another test unless I enable it manually.