using System.Collections; using System.Collections.Generic; using UnityEngine; /* -------------------------------------- Project: Programing assessment Standard: 91906 (AS3.7) v.1 School: Tauranga Boys' College Author: Rauputu Noah Phizacklea Date: August 2024 Unity: 2021.3.18f --------------------------------------- */ public class HitFlash : MonoBehaviour { [SerializeField] private Material flashMaterial; // Material used for the flash effect [SerializeField] private float flashDuration; // Duration of the flash effect private SpriteRenderer spriteRenderer; // SpriteRenderer to apply the flash effect private Material originalMaterial; // Original material of the SpriteRenderer private Coroutine flashRoutine; // Reference to the currently running flash routine void Start() { spriteRenderer = GetComponent(); // Get the SpriteRenderer component originalMaterial = spriteRenderer.material; // Save the original material } public void Flash() { if (flashRoutine != null) // If a flash is already in progress { StopCoroutine(flashRoutine); // Stop the existing flash } flashRoutine = StartCoroutine(FlashRoutine()); // Start a new flash routine } private IEnumerator FlashRoutine() { spriteRenderer.material = flashMaterial; // Change to the flash material yield return new WaitForSeconds(flashDuration); // Wait for the flash duration spriteRenderer.material = originalMaterial; // Restore the original material flashRoutine = null; // Clear the flash routine reference } }