mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-24 00:50:59 +00:00
make pillows disappear when touching the floor
make them reappear when Mother is in the room
This commit is contained in:
parent
5b6fd11745
commit
38acd0dc6e
Binary file not shown.
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user