From 7f3339d33d05f90efa59290ffe3511f6e2e7c07c Mon Sep 17 00:00:00 2001 From: Patrice Vignola Date: Sun, 23 Aug 2015 02:11:09 -0400 Subject: [PATCH 1/2] Add the first pass of the pillow spawners --- Assets/Prefabs/Bed.prefab | Bin 8892 -> 9200 bytes Assets/Prefabs/BunkBed.prefab | Bin 11372 -> 11800 bytes Assets/Scenes/PatScene.unity | Bin 59364 -> 57412 bytes Assets/Scripts/Bed.cs | 107 ++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/Assets/Prefabs/Bed.prefab b/Assets/Prefabs/Bed.prefab index 840c6a18b7d0d51845ac9c35537ff89517d28378..4a8f17d440af1091d1daedcc8178e8ce83c04145 100644 GIT binary patch delta 447 zcmdnv`oUd*fkFB*1B3Dh1_lOxAp65a0Zq~9I)?_iX}OytzuNt0d9wDdJWw)fqn|TV zJtG4ng9eai2E;r-ECIv}91K8FCWd9ixg7(9_D{-6O)g;wO3g_u$t+6^$S=+;$;{7Vs9>mMsM@@PX_Dw>ABh)?vN1q& z{sTb~$UGoekp7(&OtUjEBuoyJl4oR}TqxBc5taU{;Cl2^r*5XsTd_yyoMi&5W?-27 zP*!=fjC2C?WG-ngz6N_+uI=_9sm7_!`!`RK`@k#;G>Ads(K@jDvuDnLWbHxP#3vt+ Y6OaZ43W|$?e5j7e6O|+5j=4<&-z`$RsdJd|@%& o57f!c5t5tvWaO9`V50SI_E6YolXog`Z&{rE|Mw*y!iX zG;{z_;bL?aKH%-n~jbXIkd_q-(jpgi_GkYgL(Dq@uzPMoj ZWCI-^h)9FZlF2a|5ZA?>F7(VAxun1}$h^5!Nw2mm-v}*xBK!^puI%Zgny45MRLV*IJMVtbn!%PP< zUBK55qH}|pEt-iIZ?d39t&1+mhL*S}bGltOmy|hOw_lx8*?TS}U`ck9^PY3>^PK0r zU-#U<9(LIiHkpu;w+WHv6GFz}+J!Tjp*QN23XSAhe}6ya+b4fDm)3|^XO&U$-ol7D zx=-v|b)Ck0IY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*^jL0`a%-7((E>WWR(yq9k1#<(OsQhtL^9m+r@WjSG` zno6AJ%r5YI5zVpbcKTkChnY>aNIB@nKBybk*2o<8zDB==m8N>S0xPZcqem7xp-AkF(=FBGV_^-n!6aT)0_Y%K-`~!SN*R^e@pTf$(c6tw1 z5@DG`Io6|}KYqK3tpuQ(iT;tiijgvnuCBkhlXYD_dJHT5elpjXGl%@+J?hh$(YSHp z9<865+{{*r8Z~##m1yc|G}2eQO$e=8u&aORlp$X-{r{%GJ|o5YW3}6jwJ|ib%}582#FD+)N;Y?_*4q5OGBIUI>XHnU^fVf2nMohC z#!*wts+f%QMOLddHC1Sy591V?|Lb`2?lWqGZ}b_d# z_fLvmoRKECK_d+d$ns|+dD}wnSZLs8l6LCk8%!}`WaDb}TI749txI`ZFlgO0SG%ZsFe_Na)o#Y;&!Fcncs zkk0e$q>s=2pU9dhaB(OUS=!TMqUCPWa$I6QKUSN`mqpKZ=&IaoOYL#UPqXwI*CGZkJW%ZyB~RFFH1t6tS-sJUfgbKwwc|af zCehFOQ?;GF2=&~lgkxcvIwfxVAjsF8`LBzWN 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") + { + + } + }*/ } From f6ae2d05c0b8107f0ff809b59531bfd4dda4cb89 Mon Sep 17 00:00:00 2001 From: Patrice Vignola Date: Sun, 23 Aug 2015 02:21:51 -0400 Subject: [PATCH 2/2] Fix a bug in the pillow spawner script --- Assets/Scripts/Bed.cs | 16 +++++----------- Assets/Scripts/Child.cs | 3 +++ Assets/Scripts/Pillow.cs | 7 +++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Bed.cs b/Assets/Scripts/Bed.cs index e70f0e1..fb4e896 100644 --- a/Assets/Scripts/Bed.cs +++ b/Assets/Scripts/Bed.cs @@ -41,6 +41,11 @@ public class Bed : MonoBehaviour _nextSpawnDelay = GetNextSpawnDelay(); } } + else if (_currentPillow.IsOwned) + { + _currentPillow = null; + _elapsedTime = 0f; + } } private void SpawnPillow() @@ -89,17 +94,6 @@ 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) { 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 () {