rabidus-test/Assets/DisableAfterFinish.cs

42 lines
871 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisableAfterFinish : MonoBehaviour
{
private DisableAfterFinishController disableController;
[SerializeField] private GameObject _target;
public bool DisableState = false;
private void Awake()
{
disableController = FindObjectOfType<DisableAfterFinishController>();
}
private void OnEnable()
{
if (disableController == null)
return;
disableController.DoDisable += Disable;
}
private void OnDisable()
{
if (disableController == null)
return;
disableController.DoDisable -= Disable;
}
private void Disable()
{
if (_target == null)
gameObject.SetActive(DisableState);
else
_target.SetActive(DisableState);
}
}