36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class SelectedCounterVisual : MonoBehaviour {
|
|
[SerializeField] private BaseCounter baseCounter;
|
|
[SerializeField] private GameObject[] visualGameObjectArray;
|
|
|
|
private void Start() {
|
|
if (Player.LocalInstance != null)
|
|
Player.LocalInstance.OnSelectedCounterChanged += Player_OnSelectedCounterChanged;
|
|
else
|
|
Player.OnAnyPlayerSpawned += Player_OnyAnyPlayerSpawned;
|
|
}
|
|
|
|
private void Player_OnyAnyPlayerSpawned(object sender, EventArgs e) {
|
|
if (Player.LocalInstance != null) {
|
|
Player.LocalInstance.OnSelectedCounterChanged -= Player_OnSelectedCounterChanged;
|
|
Player.LocalInstance.OnSelectedCounterChanged += Player_OnSelectedCounterChanged;
|
|
}
|
|
}
|
|
|
|
private void Player_OnSelectedCounterChanged(object sender, SelectedCounterChangedEventArgs e) {
|
|
if (e.SelectedCounter == baseCounter)
|
|
Show();
|
|
else
|
|
Hide();
|
|
}
|
|
|
|
private void Show() {
|
|
foreach (GameObject visualGameObject in visualGameObjectArray) visualGameObject.SetActive(true);
|
|
}
|
|
|
|
private void Hide() {
|
|
foreach (GameObject visualGameObject in visualGameObjectArray) visualGameObject.SetActive(false);
|
|
}
|
|
} |