Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- namespace SpartanFist
- {
- public class Twiddler : MonoBehaviour
- {
- [Header("References"), Tooltip("The switch we're twiddling")]
- public Switch toTwiddle;
- [Header("Twiddling"), Tooltip("If true, we can twiddle the switch from off to on")]
- public bool offToOn = false;
- [Tooltip("If true, we can twiddle the switch from on to off")]
- public bool onToOff = false;
- protected virtual void Twiddle()
- {
- if (toTwiddle == null) { return; }
- Twiddle(!toTwiddle.SwitchState);
- }
- protected virtual bool Twiddle(bool targetState)
- {
- if (toTwiddle == null) { return false; }
- if (targetState && offToOn && !toTwiddle.SwitchState) { toTwiddle.SwitchState = true; return true; }
- else if (!targetState && onToOff && toTwiddle.SwitchState) { toTwiddle.SwitchState = false; return true; }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment