Commit f3bdd9ba authored by Markus Schlösser's avatar Markus Schlösser
Browse files

Added Timed Toggle

parent b9a5e40b
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class TimedToggle : MonoBehaviour {
[System.Serializable]
private class BoolEvent : UnityEvent<bool> { }
[SerializeField] private bool isActive;
[SerializeField] private float onDuration;
[SerializeField] private float offDuration;
[SerializeField] private BoolEvent onStateChange;
private float time;
private bool state;
private void Start() {
state = isActive;
}
private void Update() {
if (state && time >= onDuration) {
time -= onDuration;
state = false;
onStateChange.Invoke(false);
} else if (!state && time >= offDuration) {
time -= offDuration;
state = true;
onStateChange.Invoke(true);
}
time += Time.deltaTime;
}
}
fileFormatVersion: 2
guid: 3bee911a8822169419481ec225f9993a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment