48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace InfallibleCode
|
|
{
|
|
public class WaterInteract : MonoBehaviour, IInteractable
|
|
{
|
|
[Tooltip("If you don't declare this field with an animator then the script will take the animator componenet of the gameobject it is attached to.")]
|
|
[SerializeField] private Animator _WaterAnimator;
|
|
[Tooltip("If you set this bool as true the water will go down. If set it as false then the water will go up.")]
|
|
public bool WaterGoingDown;
|
|
|
|
[SerializeField] private UnityEvent eventToInvokeAfterInteraction;
|
|
|
|
private void Start()
|
|
{
|
|
if (_WaterAnimator == null)
|
|
{
|
|
_WaterAnimator = GetComponent<Animator>();
|
|
}
|
|
}
|
|
|
|
public void SinkUpdate()
|
|
{
|
|
if (WaterGoingDown)
|
|
{
|
|
_WaterAnimator.SetBool("WaterIsGoingDown", true);
|
|
_WaterAnimator.SetBool("WaterIsGoingUp", false);
|
|
if(eventToInvokeAfterInteraction!= null)
|
|
{
|
|
eventToInvokeAfterInteraction.Invoke();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_WaterAnimator.SetBool("WaterIsGoingDown", false);
|
|
_WaterAnimator.SetBool("WaterIsGoingUp", true);
|
|
}
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
SinkUpdate();
|
|
}
|
|
}
|
|
} |