it's like my Button tries to go interractable = false; but can't do it //any help?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class RobaMarket2 : MonoBehaviour {
public Button robaMarket;
public Text coolDownText;
public float coolDown = 0.0f;
public Text marketText; //wechselt zwichen kann ausrauben und kann nicht\\
public Button mask; //button für BuyaMask script\\
void Start() {
Button btn = robaMarket.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void Update() {
int hours = Mathf.FloorToInt(coolDown / 3600F);
int minutes = Mathf.FloorToInt((coolDown % 3600)/60);
int seconds = Mathf.FloorToInt(coolDown % 60);
string formattedTime = string.Format ("{0:00}:{1:00}:{2:00}", hours, minutes,seconds);
if (coolDown > 0) //wenn der cooldown über 0 ist
{
robaMarket.interactable = false; // rob a market nicht draufdrückbar
coolDown -= Time.deltaTime; // zeit wird - gerechnet
coolDownText.text = formattedTime; // kommt der text
}
if (coolDown < 0) //wenn cooldown unter 0 ist
{
coolDown = 0; // ist der cooldown 0
robaMarket.interactable = true; // rob a market draufdrückbar
}
if (mask.enabled == true) //wenn wir die maske noch nicht haben
{
marketText.text = "Buy a Mask!"; //kommt der text
robaMarket.interactable = false; //rob a market nicht draufdrückbar
}
if (mask.enabled == false) //wenn wir die maske haben
{
marketText.text = "Rob a Market"; //kommt der text
robaMarket.interactable = true; //rob a market draufdrückbar
}
if (coolDown > 0) //wenn cooldown über 0 ist
{
coolDownText.text = formattedTime; // kommt der text
robaMarket.interactable = false;
}
}
void TaskOnClick() {
robaMarket.interactable = false;
coolDown = 180f;
}
}
Comment
Your answer
Follow this Question
Related Questions
Fast start and ending at jump but slow middle. 0 Answers
unable to attack enemy objects? 1 Answer
IndexOutOfRangeExeption! This doesent even affect my gameplay, it just is there to be annoying! 1 Answer
Unity for each JSONnode in JSONObject 0 Answers
Can I switch between 64 bit and 32 bit computer when creating my game? 2 Answers