using System.Collections; using System.Collections.Generic; using UnityEngine; public class FadingPlatform : MonoBehaviour { private SpriteRenderer spriteRenderer; private BoxCollider2D col; private EdgeCollider2D edge; public float fadeTime; public float refractoryTime; private bool gone; private AudioSource audioSource; // Reference to the AudioSource component public AudioClip fadeSound; // The sound clip to be played void Start() { spriteRenderer = GetComponent(); col = GetComponent(); edge = GetComponent(); gone = false; audioSource = GetComponent(); } void Update() { if(gone) { StartCoroutine(Switch()); } } void OnTriggerEnter2D(Collider2D edge) { if(!gone){ StartCoroutine(Switch()); } } // Muss IEnumerator sein weil ich ansonsten den Timer nicht implementieren kann IEnumerator Switch(){ if(gone) { yield return new WaitForSeconds (refractoryTime); spriteRenderer.enabled = true; col.enabled = true; edge.enabled = true; gone = false; } else { yield return new WaitForSeconds (fadeTime); spriteRenderer.enabled = false; col.enabled = false; edge.enabled = false; gone = true; audioSource.PlayOneShot(fadeSound); } } }