コインが足りないとボタンを押せなくする方法が分かりません。
いろいろと試行錯誤しましたが、なかなかうまくいきません。
以下のコードを、どのようにすればコインが足りないときにボタンが押せなくなりますか?
using UnityEngine; using UnityEngine.UI; public class Coin : MonoBehaviour { // Use this for initialization void Start() { } public int Money = 5000; private int score; public bool Pay(int value) { if (value < Money) { Money -= value; Debug.Log("Money : " + Money); return true; } return false; } // Update is called once per frame void Update() { } }
Button.cs
using UnityEngine; using UnityEngine.EventSystems; public class Button : MonoBehaviour { public Coin coin; // Use this for initialization void Start() { } // Update is called once per frame void Update() { } public void ButtonClick(BaseEventData data) { Debug.Log("clicked"); coin.Pay(500); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。