Looking-Glass/Assets/scripts/Lockable.cs

34 lines
871 B
C#
Raw Permalink Normal View History

2024-02-27 19:03:50 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// if locked is true, calling TryUnlock will call StartUnlock, otherwise it will call FailedUnlock.
public abstract class Lockable : MonoBehaviour
{
public bool looping = true;
public bool loopingAfterUnlock = false;
public bool locked = true;
private bool runBefore = false;
private bool unlockedBefore = false;
public abstract void StartUnlock();
public abstract void FailedUnlock();
public void TryUnlock(){
if((!runBefore) | looping){
runBefore = true;
if(!locked){
if((!unlockedBefore) | loopingAfterUnlock){
unlockedBefore = true;
StartUnlock();
}
}
else{
FailedUnlock();
}
}
}
}