mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-25 09:30:58 +00:00
Add the first pass of the mom behavior
This commit is contained in:
parent
93832dcaa8
commit
2af4b94ddc
Binary file not shown.
@ -7,13 +7,18 @@ public class Child : MonoBehaviour
|
|||||||
public float Speed = 10f;
|
public float Speed = 10f;
|
||||||
public float JumpForce = 10f;
|
public float JumpForce = 10f;
|
||||||
public GameObject GroundCheck;
|
public GameObject GroundCheck;
|
||||||
|
public Pillow pillow;
|
||||||
|
|
||||||
private Rigidbody _rb;
|
private Rigidbody _rb;
|
||||||
private bool _isGrounded = false;
|
private bool _isGrounded = false;
|
||||||
private float _xValue;
|
private float _xValue;
|
||||||
private float _zValue;
|
private float _zValue;
|
||||||
public Pillow pillow;
|
private bool _isSleeping;
|
||||||
|
|
||||||
|
public bool IsSleeping
|
||||||
|
{
|
||||||
|
get { return _isSleeping; }
|
||||||
|
}
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@ -27,7 +32,6 @@ public class Child : MonoBehaviour
|
|||||||
Debug.Log(_isGrounded);
|
Debug.Log(_isGrounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnTriggerEnter(Collider other) {
|
void OnTriggerEnter(Collider other) {
|
||||||
if (other.tag == "Pillow") {
|
if (other.tag == "Pillow") {
|
||||||
|
|
||||||
@ -78,4 +82,16 @@ public class Child : MonoBehaviour
|
|||||||
_rb.AddForce(new Vector3(0f, JumpForce, 0f));
|
_rb.AddForce(new Vector3(0f, JumpForce, 0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Sleep()
|
||||||
|
{
|
||||||
|
_isSleeping = IsOnBed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsOnBed()
|
||||||
|
{
|
||||||
|
Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.149f, 1 << LayerMask.NameToLayer("Bed"));
|
||||||
|
|
||||||
|
return colliders.Length > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public class ChildController : MonoBehaviour
|
|||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
InputManager.Instance.PushActiveContext("Gameplay", (int)PlayerNumber);
|
InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber);
|
||||||
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis);
|
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis);
|
||||||
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons);
|
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons);
|
||||||
|
|
||||||
@ -57,6 +57,11 @@ public class ChildController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
_child.Jump();
|
_child.Jump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input.Actions.Contains("Sleep"))
|
||||||
|
{
|
||||||
|
_child.Sleep();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
47
Assets/Scripts/MomBehavior.cs
Normal file
47
Assets/Scripts/MomBehavior.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class MomBehavior : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Child[] Children;
|
||||||
|
|
||||||
|
public Text WarningText;
|
||||||
|
public float MinTriggerTime = 60f;
|
||||||
|
public float MaxTriggerTime = 90f;
|
||||||
|
public float WarningHeadsupTime = 5f;
|
||||||
|
|
||||||
|
private float _elapsedTime = 0f;
|
||||||
|
|
||||||
|
private float _nextTriggerTime;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
_nextTriggerTime = GetNextTriggerTime();
|
||||||
|
Debug.Log("NextTrigger: " + _nextTriggerTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
// When the mom hasn't been triggered for a while, it can appear anytime between 2 borders
|
||||||
|
|
||||||
|
_elapsedTime += Time.deltaTime;
|
||||||
|
|
||||||
|
if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime)
|
||||||
|
{
|
||||||
|
WarningText.gameObject.SetActive(true);
|
||||||
|
}
|
||||||
|
else if (_elapsedTime >= _nextTriggerTime)
|
||||||
|
{
|
||||||
|
WarningText.gameObject.SetActive(false);
|
||||||
|
_nextTriggerTime = GetNextTriggerTime();
|
||||||
|
|
||||||
|
_elapsedTime = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float GetNextTriggerTime()
|
||||||
|
{
|
||||||
|
return UnityEngine.Random.Range(MinTriggerTime, MaxTriggerTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Scripts/MomBehavior.cs.meta
Normal file
12
Assets/Scripts/MomBehavior.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc7c5ec2b3918f14591f5f055ded72ef
|
||||||
|
timeCreated: 1440227199
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user