Files
2025-05-29 22:31:40 +03:00

65 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using InfallibleCode;
//[RequireComponent(typeof(ExaminableItem))]
//[RequireComponent(typeof(StopSound))]
//[RequireComponent(typeof(PlaySound))]
public class PhoneAnswered : MonoBehaviour
{
[SerializeField] private ExaminableItem examinableItem;
[SerializeField] StopSound stopCallingSound;
[SerializeField] PlaySound playAnsweringSound;
[SerializeField] StopSound stopAnsweringSound;
public bool _hasAnswered;
public bool _hasEndedCall;
private void Awake()
{
if (examinableItem == null)
{
examinableItem = GetComponent<ExaminableItem>();
}
}
public void Update()
{
if (!_hasEndedCall) {
if (examinableItem.IsInteractingWithItem == true && !_hasAnswered)
{
stopCallingSound.StopThisSoundImmediately();
playAnsweringSound.PlayThisSoundLooped();
print("Answered phone");
_hasAnswered = true;
}
else if (examinableItem.HasInteractedWithItem && _hasAnswered)
{
stopAnsweringSound.StopThisSoundImmediately();
print("Closed phone");
_hasEndedCall = true;
}
}
}
//private void OnTriggerStay(Collider col)
//{
// if (col.gameObject.tag == "Player" && !_hasEndedCall)
// {
// if (examinableItem.IsInteractingWithItem == true && !_hasAnswered)
// {
// stopCallingSound.StopThisSound();
// playAnsweringSound.PlayThisSoundLooped();
// print("Answered phone");
// _hasAnswered = true;
// }
// else if (examinableItem.HasInteractedWithItem && _hasAnswered)
// {
// stopAnsweringSound.StopThisSound();
// print("Closed phone");
// _hasEndedCall = true;
// }
// }
//}
}