Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TriggerSleepStates : MonoBehaviour
- {
- static DragonStates States = DragonStates.Instance;
- public Rigidbody DragonRigidBody;
- // Create a reference to the animator component
- private Animator animator;
- public float IdleBeforeSleep;
- //TODO set up falling asleep after a period of time, possibly rotate the camera in a circle while sleeping.?
- // Use this for initialization
- void Start ()
- {
- // initialise the reference to the animator component
- animator = GetComponent<Animator>();
- }
- void Update()
- {
- if (Input.GetButtonDown("Nap"))
- {
- if (States.CurrentDragonState == DragonStates.DragonState.Idle)
- {
- States.SetSleepFallAsleep();
- animator.SetBool("FallAsleep", true);
- }
- else if (States.CurrentDragonState == DragonStates.DragonState.Sleeping)
- {
- States.SetSleepWakeUp();
- animator.SetBool("WakeUp", true);
- States.SetIdle();
- }
- }
- if (States.CurrentDragonState == DragonStates.DragonState.Sleeping)
- {
- if (!DragonRigidBody.IsSleeping())
- {
- DragonRigidBody.Sleep();
- }
- }
- else
- {
- if (DragonRigidBody.IsSleeping())
- DragonRigidBody.WakeUp();
- }
- if (Input.GetButtonUp("Nap") && States.CurrentDragonState == DragonStates.DragonState.Idle)
- {
- animator.SetBool("WakeUp", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement