74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace InfallibleCode
|
|
{
|
|
public class BookSwitch : MonoBehaviour, IInteractable
|
|
{
|
|
[SerializeField] private UnityEvent bookSwitchPushedInEvent;
|
|
[SerializeField] private UnityEvent bookswitchPushedOutEvent;
|
|
|
|
public bool bookSwitchIsPushedIn;
|
|
|
|
[SerializeField] private float _LerpTime;
|
|
|
|
[SerializeField] Animator _SwitchAnimator;
|
|
|
|
[SerializeField] private float animationTimeToComplete = 0.5f;
|
|
|
|
public bool CanPushBook = true;
|
|
private bool CanPressButtonDown = true;
|
|
|
|
private void Awake()
|
|
{
|
|
if (bookSwitchIsPushedIn)
|
|
{
|
|
_SwitchAnimator.SetTrigger("BookPushedIn");
|
|
}
|
|
else
|
|
{
|
|
_SwitchAnimator.SetTrigger("BookPushedOut");
|
|
}
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
if (CanPushBook && CanPressButtonDown/* && !PlayerManager.GetInstance().LaraCroftPlayerController.IsInAir*/)
|
|
{
|
|
if (!bookSwitchIsPushedIn)
|
|
{
|
|
StartCoroutine(PushBookSwitchIn());
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(PushBookSwitchOut());
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator PushBookSwitchIn()
|
|
{
|
|
CanPressButtonDown = false;
|
|
yield return new WaitForSeconds(animationTimeToComplete);
|
|
//door.OpenDoor();
|
|
bookSwitchIsPushedIn = true;
|
|
bookSwitchPushedInEvent.Invoke();
|
|
yield return new WaitForSeconds(0.1f);
|
|
CanPressButtonDown = true;
|
|
_LerpTime = 0.0f;
|
|
}
|
|
|
|
IEnumerator PushBookSwitchOut()
|
|
{
|
|
CanPressButtonDown = false;
|
|
yield return new WaitForSeconds(animationTimeToComplete);
|
|
bookSwitchIsPushedIn = false;
|
|
bookswitchPushedOutEvent.Invoke();
|
|
yield return new WaitForSeconds(0.1f);
|
|
CanPressButtonDown = true;
|
|
_LerpTime = 0.0f;
|
|
}
|
|
}
|
|
} |