57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
[RequireComponent(typeof(Collider))]
|
||
|
|
public class AttentionTrigger : MonoBehaviour
|
||
|
|
{
|
||
|
|
public CameraController cameraController;
|
||
|
|
public Transform cameraPoint;
|
||
|
|
public HintManager hintManager;
|
||
|
|
public string hintText = "Похоже, здесь что-то спрятано...";
|
||
|
|
public float hintDuration = 3f;
|
||
|
|
public float fixedCameraDuration = 2.5f;
|
||
|
|
public AudioClip audioClip;
|
||
|
|
public AudioSource audioSource;
|
||
|
|
public bool destroyAfterTrigger;
|
||
|
|
|
||
|
|
private bool hasTriggered;
|
||
|
|
|
||
|
|
private void Reset()
|
||
|
|
{
|
||
|
|
GetComponent<Collider>().isTrigger = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnTriggerEnter(Collider other)
|
||
|
|
{
|
||
|
|
if (hasTriggered || !other.CompareTag("Player"))
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
hasTriggered = true;
|
||
|
|
|
||
|
|
// One trigger coordinates camera focus, UI hint, and sound cue.
|
||
|
|
cameraController?.SetFixedCamera(cameraPoint, fixedCameraDuration);
|
||
|
|
hintManager?.ShowHint(hintText, hintDuration);
|
||
|
|
|
||
|
|
if (audioClip != null)
|
||
|
|
{
|
||
|
|
if (audioSource != null)
|
||
|
|
{
|
||
|
|
audioSource.PlayOneShot(audioClip);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AudioSource.PlayClipAtPoint(audioClip, transform.position);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Collider triggerCollider = GetComponent<Collider>();
|
||
|
|
triggerCollider.enabled = false;
|
||
|
|
|
||
|
|
if (destroyAfterTrigger)
|
||
|
|
{
|
||
|
|
Destroy(gameObject, fixedCameraDuration + 1f);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|