'Is the a posibility to enable a bool and disable other one with scriptable objects in Unity?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[CreateAssetMenu(fileName = "NewItem", menuName = "Items/NewItem", order = 1)]
public class NewBehaviourScript : ScriptableObject
{
[HideInInspector]
public string buy = "BUY";
[HideInInspector]
public string OWNED = "EQUIP";
[HideInInspector]
public Color equipColor = new Color(0.53333f, 1.00000f, 0.30196f);
[HideInInspector]
public Color buyColor = new Color(1.00000f, 0.10196f, 0.10196f);
public new string name;
public float price;
public Sprite Image;
public bool Owned;
public float spreadAmmount;
public float damage;
public bool equiped;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class DisplayItems : MonoBehaviour
{
public MoneyUpdate curency;
public NewBehaviourScript item;
public TextMeshProUGUI Cost;
public TextMeshProUGUI ItemName;
public Image image;
public TextMeshProUGUI buttonText;
public Button button;
private void Update()
{
if (item.Owned)
{
buttonText.text = "" + item.OWNED;
ColorBlock cb = button.colors;
cb.normalColor = item.equipColor;
button.colors = cb;
}
else
{
buttonText.text = "" + item.buy;
ColorBlock cb = button.colors;
cb.normalColor = item.buyColor;
button.colors = cb;
}
}
void Start()
{
Cost.text = "$" + item.price;
ItemName.text = "" + item.name;
image.sprite = item.Image;
}
public void BuyWeapon()
{
if (!item.Owned && item.price <= curency.money)
{
item.Owned = true;
PlayerPrefs.SetInt("Money", (int)curency.money - (int)item.price);
}
if (item.Owned)
{
item.equiped = true;
}
}
}
When i press the button to equip, bool is gonna set to true,but when i press the other button it equip booth
That s the shop system UI,that I made with the buttons in it,can t figgure out how i can equip only one once!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
