How do I make a button become another button?
Hello there, I'm a beginner in coding and I'm struggling with this issue for the game I'm working on: I have three buttons (one for defense,one for attack and one for reload) and sometimes a random object appears on the screen and change the order of the buttons. When the change happen, the button are rotating and their icon change based on a random algorithm. For example:
Btn1=>Btn2
Btn2=>Btn3
Btn3=>Btn1
So far I've managed to deal with the icon changing but I have no idea how to make the button keep their previous interactable state.If in the above example Btn2 was not interactable I would like Btn3 to become not interactable and Btn2 to become interactable after the change happened. For now I've tried to solve the issue this way:
public class buttonChanger : MonoBehaviour
{
[SerializeField]
Button btn1;
[SerializeField]
Button btn2;
[SerializeField]
Button btn3;
Button btn1T;
Button btn2T;
Button btn3T;
void Start()
{ btn1T = btn1;
btn2T = btn2;
btn3T = btn3;
}
void Update()
{
if (timerDice == 0 && transitionBool == true)
{
btn1 = btn1T;
btn2 = btn2T;
btn3 = btn3T;
}
if (timerDice == 1 && transitionBool == true)
{
btn1 = btn1T;
btn2 = btn2T;
btn3 = btn3T;
}
if (timerDice == 2 && transitionBool == true)
{
btn1 = btn1T;
btn2 = btn3T;
btn3 = btn2T;
}
if (timerDice == 3 && transitionBool == true)
{
btn1 = btn2T;
btn2 = btn1T;
btn3 = btn3T;
}
}
I have to say I am really lost with this one, so if any of you got an idea of how I'm supposed to solve this code you will have my eternal thankfulness^^
Your answer
Follow this Question
Related Questions
How do I catch a click on a non-interactable button? 1 Answer
How can I make mobile UI buttons fire when first touched rather than released? 0 Answers
Can't disable TMPro Buttons 1 Answer
CrossPlatformInput Detect Multiple Input Headache 1 Answer
Is it possible to get the screen rect for a button regardless of its parent? 1 Answer