Остаётся возможность использования кнопок при их отключении в Unity
Отключаю кнопки при выполнении/невыполнении условий, а они, несмотря на заданные условия, обе становятся внешне неактивными, но при их нажатии начисляются деньги что после выполнения условий и их дизактивации, что до выполнения условий.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class AchMenu : MonoBehaviour
{
public int total_money;
[SerializeField] Button FirstTrp;
[SerializeField] Button SecondTrp;
[SerializeField] bool isFirst;
[SerializeField] bool isSecond;
public void GetCheker()
{
if()
}
void Start()
{
total_money = PlayerPrefs.GetInt("total_money");
isFirst = PlayerPrefs.GetInt("isFirst") == 1;
if (total_money >= 20 && isFirst == false)
{
FirstTrp.interactable = true;
}
else
{
FirstTrp.interactable = false;
}
total_money = PlayerPrefs.GetInt("total_money");
isSecond = PlayerPrefs.GetInt("isSecond") == 1;
if (total_money >= 500 && isSecond == false)
{
SecondTrp.interactable = true;
}
else
{
SecondTrp.interactable = false;
}
}
public void GetFirst(){
int money = PlayerPrefs.GetInt("total_money");
total_money += 10;
PlayerPrefs.SetInt("total_money", total_money);
isFirst = true;
PlayerPrefs.SetInt("isFirst", isFirst ? 1 : 0);
}
public void GetSecond(){
int money = PlayerPrefs.GetInt("total_money");
total_money += 100;
PlayerPrefs.SetInt("total_money", total_money);
isSecond = true;
PlayerPrefs.SetInt("isSecond", isSecond ? 1 : 0);
}
public void ToMenu()
{
SceneManager.LoadScene(0);
}
void Update()
{
}
}
Ответы (1 шт):
Автор решения: Valera Kvip
→ Ссылка
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class AchMenu : MonoBehaviour
{
public int total_money;
[SerializeField] Button FirstTrp;
[SerializeField] Button SecondTrp;
[SerializeField] bool isFirst;
[SerializeField] bool isSecond;
public void GetCheker()
{
if()
}
private void updateUI(){
FirstTrp.interactable = (total_money >= 20 && !isFirst);
SecondTrp.interactable = (total_money >= 500 && !isSecond);
}
void Start()
{
total_money = PlayerPrefs.GetInt("total_money");
isFirst = PlayerPrefs.GetInt("isFirst") == 1;
isSecond = PlayerPrefs.GetInt("isSecond") == 1;
updateUI();
}
public void GetFirst(){
total_money += 10;
PlayerPrefs.SetInt("total_money", total_money);
isFirst = true;
PlayerPrefs.SetInt("isFirst", 1);
updateUI();
}
public void GetSecond(){
total_money += 100;
PlayerPrefs.SetInt("total_money", total_money);
isSecond = true;
PlayerPrefs.SetInt("isSecond",1);
updateUI();
}
public void ToMenu()
{
SceneManager.LoadScene(0);
}
void Update()
{
}
}
Из того что есть в вопросе, можно собрать такой ответ.