I am trying to make a level selector scene where players unlock levels and it displays a picture of the level so they can track their progress.
I have done the level unlocker and selector system, Im stuck on the images being displayed on the Raw Image component.
I have got the level properties in a class, they all load perfectly fine. I need the ‘LevelTexture’ to be in that class too.
If the ‘LevelTexture’ are not in the class then it loads fine, but as soon as I move the variable into the class it no longer works.
I have a feeling its got something to do with (Texture). if its ‘(Texture)LevelImage’, it works find, but as soon as I put it in the class it now needs to be ‘level.LevelTexture’. and I have no idea where to put the (Texture) part now.
public class Level
{
public string LevelText;
public int LevelID;
public int Unlocked;
public bool IsInteractable;
public Texture LevelTexture;
public Button.ButtonClickedEvent OnClickEvent;
}
// public Texture LevelTexture;
void Start ()
{
levelManager = GameObject.FindObjectOfType<LevelManager>();
FillList();
}
void FillList()
{
foreach (var level in LevelList)
{
//Level button creation and name
GameObject newbutton = Instantiate(levelButton) as GameObject;
LevelButton button = newbutton.GetComponent<LevelButton>();
button.LevelText.text = level.LevelText;
img = (RawImage)GameObject.Find("Image").GetComponent<RawImage>();
//Level locked/unlocked
if (PlayerPrefs.GetInt("LevelsUnlocked") >= level.LevelID)
{
print("Unlocked" + level.LevelID);
level.Unlocked = 1;
level.IsInteractable = true;
img.texture = level.LevelTexture; //This line has the issue.
//img.texture = LevelTexture;
print("Image loaded: " + level.LevelTexture);
// LevelPeak.sprite = level.LevelImage;
}
//Button Update
button.unlocked = level.Unlocked;
button.GetComponent<Button>().interactable = level.IsInteractable;
button.GetComponent<Button>().onClick.AddListener(() => levelManager.LoadLevel(button.LevelText.text));
newbutton.transform.SetParent(Spacer, false);
}
}
If anyone can help it would be greatly appriciated