Human interactor inside hall
This commit is contained in:
45
Assets/Game/Scripts/HumanInteractor.cs
Normal file
45
Assets/Game/Scripts/HumanInteractor.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class HumanInteractor : MonoBehaviour
|
||||
{
|
||||
public GameObject[] showingObjects;
|
||||
public UnityEvent OnInteraction;
|
||||
public UnityEvent OnClose;
|
||||
private bool showing;
|
||||
[SerializeField]
|
||||
public bool Showing => showing;
|
||||
void Start()
|
||||
{
|
||||
Selector.OnSelectedChanged.AddListener(OnSelectionChanged);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void OnSelectionChanged(){
|
||||
Toggle(Selector.selectedHuman==this);
|
||||
}
|
||||
|
||||
public void Toggle(){
|
||||
showing = !showing;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Toggle(bool value){
|
||||
showing = value;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
public void Refresh(){
|
||||
foreach(GameObject go in showingObjects){
|
||||
go.SetActive(showing);
|
||||
}
|
||||
if(!showing){
|
||||
OnClose.Invoke();
|
||||
}else{
|
||||
OnInteraction.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user