UnityGame/Assets/Scripts/EchoLocation.cs

63 lines
1.4 KiB
C#
Raw Permalink Normal View History

2024-10-27 10:53:47 +03:00
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()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
if (echoSound != null)
{
echoSound.Play();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
if (echoLight != null)
{
echoLight.enabled = true;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
if (echoLight != null)
{
echoLight.enabled = false;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
foreach (Collider obj in objects)
{
Renderer rend = obj.GetComponent<Renderer>();
if (rend != null)
{
rend.enabled = false;
}
}
}
}