make pillows disappear when touching the floor

make them reappear when Mother is in the room
This commit is contained in:
jparent 2015-08-23 03:36:27 -04:00
parent 5b6fd11745
commit 38acd0dc6e
4 changed files with 27 additions and 6 deletions

Binary file not shown.

View File

@ -59,7 +59,7 @@ public class Child : MonoBehaviour
Pillow incomingPillow = other.GetComponent<Pillow>();
// picking up a pillow
if (this.pillow == null && !incomingPillow.IsThrown) {
if (this.pillow == null && incomingPillow.IsPickable) {
pillow = incomingPillow;

View File

@ -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<MeshRenderer>();
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<Pillow>().IsPickable = false;
other.gameObject.GetComponent<Pillow>().IsLost = true;
StartCoroutine( MakePillowDisappear(other.transform) );
}
}
IEnumerator MakePillowDisappear( Transform pillow ) {
yield return new WaitForSeconds(PillowWaitTime);
pillow.transform.parent = lostPillows.transform;
}
}

View File

@ -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;
}