mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-24 00:50:59 +00:00
Restrict the bed usage to only one child per bed
This commit is contained in:
parent
a030642c8d
commit
e76e32efe7
BIN
Assets/Prefabs/Bed.prefab
Normal file
BIN
Assets/Prefabs/Bed.prefab
Normal file
Binary file not shown.
8
Assets/Prefabs/Bed.prefab.meta
Normal file
8
Assets/Prefabs/Bed.prefab.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f2c38d0d3154bc4d8148a949b98af28
|
||||
timeCreated: 1440250095
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
22
Assets/Scripts/Bed.cs
Normal file
22
Assets/Scripts/Bed.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class Bed : MonoBehaviour
|
||||
{
|
||||
private bool _isTaken;
|
||||
|
||||
public bool IsTaken
|
||||
{
|
||||
get { return _isTaken; }
|
||||
}
|
||||
|
||||
public void Take()
|
||||
{
|
||||
_isTaken = true;
|
||||
}
|
||||
|
||||
public void Leave()
|
||||
{
|
||||
_isTaken = false;
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/Bed.cs.meta
Normal file
12
Assets/Scripts/Bed.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49fab454291c16d4185f7f6a511de185
|
||||
timeCreated: 1440250042
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -6,6 +6,7 @@ public class Child : MonoBehaviour
|
||||
{
|
||||
public float Speed = 10f;
|
||||
public float JumpForce = 10f;
|
||||
public float MaxInvulnerableTime = 2f;
|
||||
public GameObject GroundCheck;
|
||||
public Pillow pillow;
|
||||
public MomBehavior Mom;
|
||||
@ -15,6 +16,8 @@ public class Child : MonoBehaviour
|
||||
private float _xValue;
|
||||
private float _zValue;
|
||||
private bool _isSleeping;
|
||||
private float _invulnerableTime;
|
||||
private Bed _currentBed;
|
||||
public Transform target;
|
||||
|
||||
private int _index;
|
||||
@ -108,11 +111,15 @@ public class Child : MonoBehaviour
|
||||
|
||||
public bool Sleep()
|
||||
{
|
||||
_isSleeping = IsOnBed();
|
||||
Bed bed = GetBed();
|
||||
|
||||
// Temporary (only for visual cue until we get the animation)
|
||||
if (_isSleeping)
|
||||
if (bed != null && !bed.IsTaken)
|
||||
{
|
||||
_currentBed = bed;
|
||||
bed.Take();
|
||||
_isSleeping = true;
|
||||
|
||||
// Temporary (only for visual cue until we get the animation)
|
||||
transform.localEulerAngles = new Vector3(90f, transform.localEulerAngles.y, transform.localEulerAngles.z);
|
||||
}
|
||||
|
||||
@ -123,23 +130,48 @@ public class Child : MonoBehaviour
|
||||
{
|
||||
_isSleeping = false;
|
||||
|
||||
_currentBed.Leave();
|
||||
|
||||
_currentBed = null;
|
||||
|
||||
// Temporary (only for visual cue until we get the animation)
|
||||
transform.localEulerAngles = new Vector3(0f, transform.localEulerAngles.y, transform.localEulerAngles.z);
|
||||
}
|
||||
|
||||
private bool IsOnBed()
|
||||
private Bed GetBed()
|
||||
{
|
||||
Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Bed"));
|
||||
|
||||
return colliders.Length > 0;
|
||||
return colliders.Length > 0 ? colliders[0].GetComponent<Bed>() : null;
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Lava")
|
||||
{
|
||||
Debug.Log("Player " + _index + " entered lava. Lose one life.");
|
||||
TakeLavaDamage();
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Lava")
|
||||
{
|
||||
// TODO: Lose a life (probably) and become immune for ~ 2 or 3 seconds
|
||||
Debug.Log("Player " + _index + " is standing on lava.");
|
||||
_invulnerableTime += Time.deltaTime;
|
||||
|
||||
if (_invulnerableTime >= MaxInvulnerableTime)
|
||||
{
|
||||
Debug.Log("Player " + _index + " is still standing on lava. Lose one life.");
|
||||
TakeLavaDamage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TakeLavaDamage()
|
||||
{
|
||||
// TODO: Lose a life (probably) and become immune for ~ 2 or 3 seconds
|
||||
|
||||
_invulnerableTime = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user