66 lines
1.4 KiB
C#
66 lines
1.4 KiB
C#
using System.Collections;
|
|
using Components;
|
|
using UnityEngine;
|
|
|
|
public class BoxInteractiveComponent : InteractiveComponent
|
|
{
|
|
public bool isOpen;
|
|
|
|
public BoxInteractiveComponent(BoxInteractable interactable)
|
|
{
|
|
this.interactable = interactable;
|
|
}
|
|
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
|
|
public override void Interact()
|
|
{
|
|
// Open the box
|
|
Debug.Log("Box Interact");
|
|
|
|
isOpen = true;
|
|
|
|
// get the box animator
|
|
var boxAnimator = GetComponent<Animator>();
|
|
// playSound();
|
|
var clipInfo = boxAnimator.GetCurrentAnimatorClipInfo(0);
|
|
var animationLength = clipInfo[0].clip.length;
|
|
|
|
boxAnimator.enabled = true;
|
|
boxAnimator.SetTrigger("chest-open");
|
|
|
|
// set active box id
|
|
BoxManager.Instance.SetActiveBox(interactable.id);
|
|
|
|
StartCoroutine(WaitForAnimation(animationLength));
|
|
|
|
|
|
// wait for animation to finish
|
|
|
|
|
|
// play open animation and sound
|
|
// boxAnimator.SetTrigger("Open");
|
|
|
|
// check if box is locked.
|
|
/*if (box.isLocked)
|
|
{
|
|
Debug.Log("Box is locked");
|
|
return;
|
|
}*/
|
|
|
|
// open the inventory UI and set the active box id.
|
|
}
|
|
|
|
private IEnumerator WaitForAnimation(float animationLength)
|
|
{
|
|
yield return new WaitForSeconds(animationLength);
|
|
UIManager.Instance.ToggleInventory();
|
|
}
|
|
} |