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 b4ec123..cf9c8e7 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..e70f0e1 100644 --- a/Assets/Scripts/Bed.cs +++ b/Assets/Scripts/Bed.cs @@ -3,13 +3,82 @@ 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(); + } + } + } + + 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 +88,42 @@ public class Bed : MonoBehaviour { _isTaken = false; } + + void OnCollisionExit(Collision col) + { + Debug.Log(_currentPillow != null && col.gameObject == _currentPillow.gameObject); + + if (_currentPillow != null && col.gameObject == _currentPillow.gameObject) + { + _currentPillow = null; + _elapsedTime = 0f; + } + } + + /* + 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") + { + + } + }*/ }