diff --git a/Assets/Scenes/PatScene.unity b/Assets/Scenes/PatScene.unity index 9a4d869..027082a 100644 Binary files a/Assets/Scenes/PatScene.unity and b/Assets/Scenes/PatScene.unity differ diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 9342307..77ce71a 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -7,13 +7,18 @@ public class Child : MonoBehaviour public float Speed = 10f; public float JumpForce = 10f; public GameObject GroundCheck; + public Pillow pillow; private Rigidbody _rb; private bool _isGrounded = false; private float _xValue; private float _zValue; - public Pillow pillow; + private bool _isSleeping; + public bool IsSleeping + { + get { return _isSleeping; } + } void Awake() { @@ -27,7 +32,6 @@ public class Child : MonoBehaviour Debug.Log(_isGrounded); } - void OnTriggerEnter(Collider other) { if (other.tag == "Pillow") { @@ -78,4 +82,16 @@ public class Child : MonoBehaviour _rb.AddForce(new Vector3(0f, JumpForce, 0f)); } } + + public void Sleep() + { + _isSleeping = IsOnBed(); + } + + private bool IsOnBed() + { + Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Bed")); + + return colliders.Length > 0; + } } diff --git a/Assets/Scripts/ChildController.cs b/Assets/Scripts/ChildController.cs index 54826bf..8c4cef5 100644 --- a/Assets/Scripts/ChildController.cs +++ b/Assets/Scripts/ChildController.cs @@ -13,7 +13,7 @@ public class ChildController : MonoBehaviour void Awake() { - InputManager.Instance.PushActiveContext("Gameplay", (int)PlayerNumber); + InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber); InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis); InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons); @@ -57,6 +57,11 @@ public class ChildController : MonoBehaviour { _child.Jump(); } + + if (input.Actions.Contains("Sleep")) + { + _child.Sleep(); + } } } diff --git a/Assets/Scripts/MomBehavior.cs b/Assets/Scripts/MomBehavior.cs new file mode 100644 index 0000000..b05b7b4 --- /dev/null +++ b/Assets/Scripts/MomBehavior.cs @@ -0,0 +1,47 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; + +public class MomBehavior : MonoBehaviour +{ + public Child[] Children; + + public Text WarningText; + public float MinTriggerTime = 60f; + public float MaxTriggerTime = 90f; + public float WarningHeadsupTime = 5f; + + private float _elapsedTime = 0f; + + private float _nextTriggerTime; + + void Awake() + { + _nextTriggerTime = GetNextTriggerTime(); + Debug.Log("NextTrigger: " + _nextTriggerTime); + } + + void Update() + { + // When the mom hasn't been triggered for a while, it can appear anytime between 2 borders + + _elapsedTime += Time.deltaTime; + + if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime) + { + WarningText.gameObject.SetActive(true); + } + else if (_elapsedTime >= _nextTriggerTime) + { + WarningText.gameObject.SetActive(false); + _nextTriggerTime = GetNextTriggerTime(); + + _elapsedTime = 0f; + } + } + + private float GetNextTriggerTime() + { + return UnityEngine.Random.Range(MinTriggerTime, MaxTriggerTime); + } +} diff --git a/Assets/Scripts/MomBehavior.cs.meta b/Assets/Scripts/MomBehavior.cs.meta new file mode 100644 index 0000000..d1165d8 --- /dev/null +++ b/Assets/Scripts/MomBehavior.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dc7c5ec2b3918f14591f5f055ded72ef +timeCreated: 1440227199 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: