So I’m making a Level Select System, which should switch the image of a button once it’s unlocked. I use a sprite as texture, but “button.image” does only work with “Image” and not with “Texture2D” or "Texture that I would have to use. Edit: I’ve also noticed, that tmptext = button.GetComponentInChildren<TMP_Text>();
and string gameObjectName = button.name;
don’t work. I would appreciate help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.UI;
public class SwitchToLevel : MonoBehaviour
{
public bool locked;
public int Level;
public int LevelCount;
int accessibleLevels;
public Image lockedTexture;
public Image unlockedTexture;
public Button button;
TMP_Text tmptext;
void Start()
{
accessibleLevels = UnlockNextLevel.instance.getLockState();
string gameObjectName = button.name;
float requestedLevel = float.Parse(gameObjectName);
if (requestedLevel <= accessibleLevels)
{
locked = false;
}
}
void Update()
{
if (locked == false)
{
tmptext = button.GetComponentInChildren<TMP_Text>();
tmptext.enabled = false;
button.image = unlockedTexture;
}
else
{
button.image = lockedTexture;
}
}
public void LevelToGo()
{
if (locked == false)
{
// hier ist ne Zeile die den Typ zum Level sendet
// some german, ignore this
}
else
{
}
}
}