using UnityEngine; using System.Collections; using System.Collections.Generic; public class OutlineEffectController : MonoBehaviour { public float radius = 5f; public float effectDuration = 3f; public LayerMask outlineLayer; private List affectedRenderers = new List(); private bool isEffectActive = false; void Update() { if (Input.GetKeyDown(KeyCode.C)) { if (!isEffectActive) { StartCoroutine(ActivateOutlineEffect()); } } } IEnumerator ActivateOutlineEffect() { isEffectActive = true; ApplyOutline(); yield return new WaitForSeconds(effectDuration); RemoveOutline(); isEffectActive = false; } void ApplyOutline() { Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius); foreach (Collider col in hitColliders) { if (((1 << col.gameObject.layer) & outlineLayer.value) != 0) { Renderer renderer = col.GetComponent(); if (renderer != null && !affectedRenderers.Contains(renderer)) { affectedRenderers.Add(renderer); renderer.enabled = true; } } } } void RemoveOutline() { foreach (Renderer renderer in affectedRenderers) { if (renderer != null) { renderer.enabled = false; } } affectedRenderers.Clear(); } }