Roulette/Assets/Scripts/Chip.cs

40 lines
925 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Chip : MonoBehaviour
{
public float value;
Outline outline;
void Awake(){
outline = GetComponent<Outline>();
RouletteManager.RegisterChip(this);
RouletteManager.OnMoneyAvailablChanged.AddListener(OnMoneyChanged);
GetComponent<Button>().onClick.AddListener(OnClicked);
}
void OnMoneyChanged(float newMoney){
gameObject.SetActive(newMoney >= value);
}
void OnClicked(){
RouletteManager.SelectedChip = value;
}
public void OnSelectedChanged(float newVal){
outline.effectColor = new Color(1,1,1, (newVal == value) ? 0.5f : 0);
}
void OnValidate(){
if(value == 0){
try{
value = float.Parse(gameObject.name.Replace("chip_",""));
}catch{}
}
}
}