- Home /
Panel GameObject not activating when called from another script
I want to enable my panel gameobject when I interact with something but it doesn't get enabled when I tell it to do so. I referenced it in the inspector and the console doesn't show any errors. I'm calling the SetDetailText function in another script. And what's weird is that the text does get updated AFTER I stop the game.
Here is my code:
public class GameManager : MonoBehaviour
{
//Objects
public GameObject statusPanel;
public Text statusText;
//Private
float textCooldownTime;
void Start()
{
statusPanel.SetActive(false);
textCooldownTime = 2.0f;
}
void Update()
{
if (statusPanel.activeSelf)
{
textCooldownTime -= Time.deltaTime;
if (textCooldownTime < 0)
{
statusPanel.SetActive(false);
textCooldownTime = 2.0f;
}
}
}
public void SetDetailText(string details)
{
statusPanel.SetActive(true);
statusText.text = details;
}
}
Answer by FlaSh-G · May 06, 2020 at 04:28 AM
textCooldownTime
isn't reset to 2.0 when SetDetailText is called. This means that it should work once, but the second time you do this, the following Update will immediately deactivate the panel again, as textCooldownTime
is still < 0
.
Your answer
Follow this Question
Related Questions
Panel GameObject not activating 0 Answers
How to reactivate items ? 4 Answers
Update list on mouse click 1 Answer
GameObjects that I deactivate are reactivated immediately 0 Answers
Multiple Cars not working 1 Answer