63 lines
1.4 KiB
C#
63 lines
1.4 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class EchoLocation : MonoBehaviour
|
|
{
|
|
public float revealRadius = 10f;
|
|
public float revealDuration = 0.5f;
|
|
public LayerMask revealLayer;
|
|
public Light echoLight;
|
|
public AudioSource echoSound;
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.E))
|
|
{
|
|
StartCoroutine(Reveal());
|
|
}
|
|
}
|
|
|
|
IEnumerator Reveal()
|
|
{
|
|
// Âîñïðîèçâåäåíèå çâóêà
|
|
if (echoSound != null)
|
|
{
|
|
echoSound.Play();
|
|
}
|
|
|
|
// Âêëþ÷åíèå ñâåòà
|
|
if (echoLight != null)
|
|
{
|
|
echoLight.enabled = true;
|
|
}
|
|
|
|
// Îáíàðóæåíèå îáúåêòîâ âîêðóã
|
|
Collider[] objects = Physics.OverlapSphere(transform.position, revealRadius, revealLayer);
|
|
foreach (Collider obj in objects)
|
|
{
|
|
Renderer rend = obj.GetComponent<Renderer>();
|
|
if (rend != null)
|
|
{
|
|
rend.enabled = true;
|
|
}
|
|
}
|
|
|
|
yield return new WaitForSeconds(revealDuration);
|
|
|
|
// Îòêëþ÷åíèå ñâåòà
|
|
if (echoLight != null)
|
|
{
|
|
echoLight.enabled = false;
|
|
}
|
|
|
|
// Ñêðûòèå îáúåêòîâ
|
|
foreach (Collider obj in objects)
|
|
{
|
|
Renderer rend = obj.GetComponent<Renderer>();
|
|
if (rend != null)
|
|
{
|
|
rend.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
} |