From 38acd0dc6eaa72eb4f0c3b1bc27f7da772bacb7c Mon Sep 17 00:00:00 2001 From: jparent Date: Sun, 23 Aug 2015 03:36:27 -0400 Subject: [PATCH] make pillows disappear when touching the floor make them reappear when Mother is in the room --- Assets/Prefabs/Pillow.prefab | Bin 8412 -> 8556 bytes Assets/Scripts/Child.cs | 2 +- Assets/Scripts/Floor.cs | 20 ++++++++++++++++++++ Assets/Scripts/Pillow.cs | 11 ++++++----- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Assets/Prefabs/Pillow.prefab b/Assets/Prefabs/Pillow.prefab index b41c59fc9f29a9b68df0c2f51cc010d70ddcbfd1..9544e8675f2db8e5bf4118826f5bcb852a46d24f 100644 GIT binary patch delta 218 zcmccP_{K?qfkDQffk82cfq{V^$S#;DpecH;sqve<{ekKCzB2l6bN`Yc4U}}==oihT z$H>6Quz;DN!4N3I2*i>=%-{)PL&R;M;!TZ?iNrzrb^rhX diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index c3dcba8..d2419fa 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -59,7 +59,7 @@ public class Child : MonoBehaviour Pillow incomingPillow = other.GetComponent(); // picking up a pillow - if (this.pillow == null && !incomingPillow.IsThrown) { + if (this.pillow == null && incomingPillow.IsPickable) { pillow = incomingPillow; diff --git a/Assets/Scripts/Floor.cs b/Assets/Scripts/Floor.cs index 49eb288..13bb637 100644 --- a/Assets/Scripts/Floor.cs +++ b/Assets/Scripts/Floor.cs @@ -8,25 +8,32 @@ public class Floor : MonoBehaviour public Material NormalMaterial; public Material LavaMaterial; + public float PillowWaitTime = 2f; + private MeshRenderer _renderer; + private GameObject lostPillows; + void Awake() { _renderer = GetComponent(); Mom.OnEnterRoom += ChangeToNormalFloor; Mom.OnLeaveRoom += ChangeToLavaFloor; + lostPillows = transform.GetChild(0).gameObject; } private void ChangeToNormalFloor() { _renderer.material = NormalMaterial; gameObject.tag = "Floor"; // Might not be necessary since the player is most likely "dead" if he touches a non-lava floor + lostPillows.SetActive(true); } private void ChangeToLavaFloor() { _renderer.material = LavaMaterial; gameObject.tag = "Lava"; // Might not be necessary since the player is most likely "dead" if he touches a non-lava floor + lostPillows.SetActive(false); } void OnDestroy() @@ -34,4 +41,17 @@ public class Floor : MonoBehaviour Mom.OnEnterRoom -= ChangeToNormalFloor; Mom.OnLeaveRoom -= ChangeToLavaFloor; } + + void OnCollisionEnter(Collision other) { + if (other.gameObject.tag == "Pillow") { + other.gameObject.GetComponent().IsPickable = false; + other.gameObject.GetComponent().IsLost = true; + StartCoroutine( MakePillowDisappear(other.transform) ); + } + } + + IEnumerator MakePillowDisappear( Transform pillow ) { + yield return new WaitForSeconds(PillowWaitTime); + pillow.transform.parent = lostPillows.transform; + } } diff --git a/Assets/Scripts/Pillow.cs b/Assets/Scripts/Pillow.cs index 09a0246..9a0af87 100644 --- a/Assets/Scripts/Pillow.cs +++ b/Assets/Scripts/Pillow.cs @@ -4,8 +4,9 @@ using System.Collections; public class Pillow : MonoBehaviour { public bool IsThrown = false; - - private bool IsPickable = true; + + public bool IsPickable = true; + public bool IsLost = false; private Collider _col; private Rigidbody _rb; @@ -27,7 +28,7 @@ public class Pillow : MonoBehaviour { } void OnCollisionEnter(Collision other) { - if (!IsPickable) { + if (!IsPickable && !IsLost) { // on first collision, revert the pillow as pickable MakePickable(); } @@ -38,8 +39,9 @@ public class Pillow : MonoBehaviour { IsThrown = true; IsPickable = false; transform.parent = null; // detach the pillow from the child object + _rb.isKinematic = false; - _col.enabled = true; + _rb.AddForce(force, ForceMode.Impulse); } @@ -47,7 +49,6 @@ public class Pillow : MonoBehaviour { IsThrown = false; IsPickable = true; - _col.enabled = true; _rb.isKinematic = false; }