58 lines
1.3 KiB
C#
Raw Normal View History

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;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
col = GetComponent<BoxCollider2D>();
edge = GetComponent<EdgeCollider2D>();
gone = false;
}
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;
}
}
}