- Home /
How can i do: When the button "play"is pressed, the player can start to move, but if not pressed the player cannot move.
void Start() { if (botao.activeInHierarchy == true) { bool enabled1 = GetComponent().enabled;
}
if (botao.activeInHierarchy == false)
{
bool enabled1 = GetComponent<PlayerMovement>().enabled = false;
}
}
Comment
Answer by rh_galaxy · Nov 12, 2021 at 12:33 PM
You should solve the problem in Update(), not in Start() which only run once. Also you don't achieve anything by setting the local variable enabled1. I'm not sure what you want to do. And what "play-button" do you mean? Maybe this can help.
void Update()
{
GetComponent<PlayerMovement>().enabled = botao.activeInHierarchy;
}