diff --git a/Assets/Prefabs/Bed.prefab b/Assets/Prefabs/Bed.prefab index 840c6a1..4a8f17d 100644 Binary files a/Assets/Prefabs/Bed.prefab and b/Assets/Prefabs/Bed.prefab differ diff --git a/Assets/Prefabs/BunkBed.prefab b/Assets/Prefabs/BunkBed.prefab index be87f47..65fd1aa 100644 Binary files a/Assets/Prefabs/BunkBed.prefab and b/Assets/Prefabs/BunkBed.prefab differ diff --git a/Assets/Scenes/PatScene.unity b/Assets/Scenes/PatScene.unity index 18035b1..87dd23a 100644 Binary files a/Assets/Scenes/PatScene.unity and b/Assets/Scenes/PatScene.unity differ diff --git a/Assets/Scripts/Bed.cs b/Assets/Scripts/Bed.cs index a5598fd..fb4e896 100644 --- a/Assets/Scripts/Bed.cs +++ b/Assets/Scripts/Bed.cs @@ -3,13 +3,87 @@ using System.Collections; public class Bed : MonoBehaviour { + // Values to balance out in playtesting + public float MinSpawnDelay = 7f; + public float MaxSpawnDelay = 15f; + + public Pillow PillowObject; + public Vector3 RelativePosition = new Vector3(1.6f, 0.5f, 0f); + private bool _isTaken; + private Pillow _currentPillow; + private float _elapsedTime; + + private float _nextSpawnDelay; public bool IsTaken { get { return _isTaken; } } + void Awake() + { + SpawnPillow(); + + _nextSpawnDelay = GetNextSpawnDelay(); + } + + void Update() + { + if (_currentPillow == null) + { + _elapsedTime += Time.deltaTime; + + if (_elapsedTime >= _nextSpawnDelay) + { + _elapsedTime = 0f; + SpawnPillow(); + _nextSpawnDelay = GetNextSpawnDelay(); + } + } + else if (_currentPillow.IsOwned) + { + _currentPillow = null; + _elapsedTime = 0f; + } + } + + private void SpawnPillow() + { + _currentPillow = Instantiate(PillowObject, transform.position, PillowObject.transform.rotation) as Pillow; + + Vector3 rot = _currentPillow.transform.eulerAngles; + rot.y = transform.eulerAngles.y - 90f; + + _currentPillow.transform.eulerAngles = rot; + + Vector3 pos = new Vector3(); + + if (Mathf.Approximately(transform.eulerAngles.y, 0f)) + { + pos = RelativePosition; + } + else if (Mathf.Approximately(transform.eulerAngles.y, 90f)) + { + pos = new Vector3(-RelativePosition.z, RelativePosition.y, -RelativePosition.x); + } + else if (Mathf.Approximately(transform.eulerAngles.y, 180f)) + { + pos = new Vector3(-RelativePosition.x, RelativePosition.y, -RelativePosition.z); + } + else if (Mathf.Approximately(transform.eulerAngles.y, 270f)) + { + pos = new Vector3(RelativePosition.z, RelativePosition.y, RelativePosition.x); + } + + _currentPillow.transform.position += pos; + } + + private float GetNextSpawnDelay() + { + return UnityEngine.Random.Range(MinSpawnDelay, MaxSpawnDelay); + } + public void Take() { _isTaken = true; @@ -19,4 +93,31 @@ public class Bed : MonoBehaviour { _isTaken = false; } + + /* + void OnCollisionEnter(Collision col) + { + // TODO: Check if the pillow is owned (otherwise it means the collision is only a player walking by) + if (col.gameObject.tag == "Pillow" && _currentPillow == null) + { + _currentPillow = col.gameObject.GetComponent(); + } + } + + void OnCollisionExit(Collision col) + { + if (_currentPillow != null && col.gameObject == _currentPillow.gameObject) + { + _currentPillow = null; + } + }*/ + + /* + void OnCollisionStay(Collision col) + { + if (col.gameObject.tag == "Player") + { + + } + }*/ } diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index c3dcba8..6cbad46 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -66,6 +66,7 @@ public class Child : MonoBehaviour pillow.transform.parent = transform; // make the pillow a child of Child pillow.transform.localPosition = new Vector3(0f, 1.5f, 0f); pillow.GetComponent().isKinematic = true; // dont make pillow obey to gravity when in a child's hands + pillow.IsOwned = true; // TODO: place the pillow correctly or animate or something... } @@ -189,6 +190,8 @@ public class Child : MonoBehaviour pillow.Throw(direction * ThrowForce); + pillow.IsOwned = false; + pillow = null; } } diff --git a/Assets/Scripts/Pillow.cs b/Assets/Scripts/Pillow.cs index 09a0246..5a66288 100644 --- a/Assets/Scripts/Pillow.cs +++ b/Assets/Scripts/Pillow.cs @@ -10,6 +10,13 @@ public class Pillow : MonoBehaviour { private Collider _col; private Rigidbody _rb; + private bool _isOwned; + + public bool IsOwned + { + get { return _isOwned; } + set { _isOwned = value; } + } // Use this for initialization void Start () {