mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-25 09:30:58 +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>();
|
Pillow incomingPillow = other.GetComponent<Pillow>();
|
||||||
|
|
||||||
// picking up a pillow
|
// picking up a pillow
|
||||||
if (this.pillow == null && !incomingPillow.IsThrown) {
|
if (this.pillow == null && incomingPillow.IsPickable) {
|
||||||
|
|
||||||
pillow = incomingPillow;
|
pillow = incomingPillow;
|
||||||
|
|
||||||
|
|||||||
@ -8,25 +8,32 @@ public class Floor : MonoBehaviour
|
|||||||
public Material NormalMaterial;
|
public Material NormalMaterial;
|
||||||
public Material LavaMaterial;
|
public Material LavaMaterial;
|
||||||
|
|
||||||
|
public float PillowWaitTime = 2f;
|
||||||
|
|
||||||
private MeshRenderer _renderer;
|
private MeshRenderer _renderer;
|
||||||
|
|
||||||
|
private GameObject lostPillows;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_renderer = GetComponent<MeshRenderer>();
|
_renderer = GetComponent<MeshRenderer>();
|
||||||
Mom.OnEnterRoom += ChangeToNormalFloor;
|
Mom.OnEnterRoom += ChangeToNormalFloor;
|
||||||
Mom.OnLeaveRoom += ChangeToLavaFloor;
|
Mom.OnLeaveRoom += ChangeToLavaFloor;
|
||||||
|
lostPillows = transform.GetChild(0).gameObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeToNormalFloor()
|
private void ChangeToNormalFloor()
|
||||||
{
|
{
|
||||||
_renderer.material = NormalMaterial;
|
_renderer.material = NormalMaterial;
|
||||||
gameObject.tag = "Floor"; // Might not be necessary since the player is most likely "dead" if he touches a non-lava floor
|
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()
|
private void ChangeToLavaFloor()
|
||||||
{
|
{
|
||||||
_renderer.material = LavaMaterial;
|
_renderer.material = LavaMaterial;
|
||||||
gameObject.tag = "Lava"; // Might not be necessary since the player is most likely "dead" if he touches a non-lava floor
|
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()
|
void OnDestroy()
|
||||||
@ -34,4 +41,17 @@ public class Floor : MonoBehaviour
|
|||||||
Mom.OnEnterRoom -= ChangeToNormalFloor;
|
Mom.OnEnterRoom -= ChangeToNormalFloor;
|
||||||
Mom.OnLeaveRoom -= ChangeToLavaFloor;
|
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;
|
public bool IsThrown = false;
|
||||||
|
|
||||||
private bool IsPickable = true;
|
public bool IsPickable = true;
|
||||||
|
public bool IsLost = false;
|
||||||
|
|
||||||
private Collider _col;
|
private Collider _col;
|
||||||
private Rigidbody _rb;
|
private Rigidbody _rb;
|
||||||
@ -27,7 +28,7 @@ public class Pillow : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnCollisionEnter(Collision other) {
|
void OnCollisionEnter(Collision other) {
|
||||||
if (!IsPickable) {
|
if (!IsPickable && !IsLost) {
|
||||||
// on first collision, revert the pillow as pickable
|
// on first collision, revert the pillow as pickable
|
||||||
MakePickable();
|
MakePickable();
|
||||||
}
|
}
|
||||||
@ -38,8 +39,9 @@ public class Pillow : MonoBehaviour {
|
|||||||
IsThrown = true;
|
IsThrown = true;
|
||||||
IsPickable = false;
|
IsPickable = false;
|
||||||
transform.parent = null; // detach the pillow from the child object
|
transform.parent = null; // detach the pillow from the child object
|
||||||
|
|
||||||
_rb.isKinematic = false;
|
_rb.isKinematic = false;
|
||||||
_col.enabled = true;
|
|
||||||
_rb.AddForce(force, ForceMode.Impulse);
|
_rb.AddForce(force, ForceMode.Impulse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +49,6 @@ public class Pillow : MonoBehaviour {
|
|||||||
IsThrown = false;
|
IsThrown = false;
|
||||||
IsPickable = true;
|
IsPickable = true;
|
||||||
|
|
||||||
_col.enabled = true;
|
|
||||||
_rb.isKinematic = false;
|
_rb.isKinematic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user