Button appears when certain points reached?
Hi, My aim is that Ui button is off when player starts the game. When he reaches 3 points button appears. Code does not seem to work. Button is off at the beginning but it does not appear when the player reaches 4 points. My code is here. What seems to be the officer problem?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ButtonAppear : MonoBehaviour {
public GameObject Button;
bool SetActive = false;
void Update()
{
if (ScoreManager.score <= 3)
{
Button.gameObject.SetActive(false);
Debug.Log("noButton");
}
else
{
Button.gameObject.SetActive(true);
Debug.Log("Button");
{
}
}
}
}
hey dude your code is fine.maybe you didn't assign the button correctly.
Have you tried to put a simple Debug.Log(Score$$anonymous$$anager.score)
in your Update function?
Answer by PersianKiller · Sep 13, 2017 at 01:27 PM
dude as I understand you attached this script to your button, and that's because when it disabled it won't be enabled !!!because it's a disabled script !!! attach your script to another object like the button's canvas,so this object is always enabled.and can enable or disable your button. :)
Answer by TooLate · Sep 13, 2017 at 10:46 AM
Weird. Code works other way around. When I turn like this: if (ScoreManagerPrinsessaHarjoitus.score >= 3)
UI button disappears when I reach 3 points. Strange that Ui button does not appear but it disappears with the code. Any suggestions?