mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-26 01:50:57 +00:00
Add the behavior of the floor changing color when the mom enters the room
This commit is contained in:
parent
5413a3bf20
commit
098cdefe14
BIN
Assets/Materials/LavaFloor.mat
Normal file
BIN
Assets/Materials/LavaFloor.mat
Normal file
Binary file not shown.
8
Assets/Materials/LavaFloor.mat.meta
Normal file
8
Assets/Materials/LavaFloor.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 17f1fb22be4247d4baff3f576a2cb9aa
|
||||||
|
timeCreated: 1440233010
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Assets/Materials/NormalFloor.mat
Normal file
BIN
Assets/Materials/NormalFloor.mat
Normal file
Binary file not shown.
8
Assets/Materials/NormalFloor.mat.meta
Normal file
8
Assets/Materials/NormalFloor.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 32997c9d92ac99e4aa7f4a0f558d918e
|
||||||
|
timeCreated: 1440235608
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
BIN
Assets/Prefabs/Floor.prefab
Normal file
BIN
Assets/Prefabs/Floor.prefab
Normal file
Binary file not shown.
8
Assets/Prefabs/Floor.prefab.meta
Normal file
8
Assets/Prefabs/Floor.prefab.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 46cbd4a59ec21ba4d8adfffd70146cb7
|
||||||
|
timeCreated: 1440235651
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@ -8,6 +8,7 @@ public class Child : MonoBehaviour
|
|||||||
public float JumpForce = 10f;
|
public float JumpForce = 10f;
|
||||||
public GameObject GroundCheck;
|
public GameObject GroundCheck;
|
||||||
public Pillow pillow;
|
public Pillow pillow;
|
||||||
|
public MomBehavior Mom;
|
||||||
|
|
||||||
private Rigidbody _rb;
|
private Rigidbody _rb;
|
||||||
private bool _isGrounded = false;
|
private bool _isGrounded = false;
|
||||||
@ -37,6 +38,13 @@ public class Child : MonoBehaviour
|
|||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
_isGrounded = IsGrounded();
|
_isGrounded = IsGrounded();
|
||||||
|
|
||||||
|
if (Mom.IsInRoom && !_isSleeping)
|
||||||
|
{
|
||||||
|
// TODO: Remove a life, kill the player, end the game, etc.
|
||||||
|
|
||||||
|
Debug.Log("Player " + _index + " is being spotted by mom.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTriggerEnter(Collider other) {
|
void OnTriggerEnter(Collider other) {
|
||||||
|
|||||||
35
Assets/Scripts/Floor.cs
Normal file
35
Assets/Scripts/Floor.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(MeshRenderer))]
|
||||||
|
public class Floor : MonoBehaviour
|
||||||
|
{
|
||||||
|
public MomBehavior Mom;
|
||||||
|
public Material NormalMaterial;
|
||||||
|
public Material LavaMaterial;
|
||||||
|
|
||||||
|
private MeshRenderer _renderer;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
_renderer = GetComponent<MeshRenderer>();
|
||||||
|
Mom.OnEnterRoom += ChangeToNormalFloor;
|
||||||
|
Mom.OnLeaveRoom += ChangeToLavaFloor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeToNormalFloor()
|
||||||
|
{
|
||||||
|
_renderer.material = NormalMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeToLavaFloor()
|
||||||
|
{
|
||||||
|
_renderer.material = LavaMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDestroy()
|
||||||
|
{
|
||||||
|
Mom.OnEnterRoom -= ChangeToNormalFloor;
|
||||||
|
Mom.OnLeaveRoom -= ChangeToLavaFloor;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Assets/Scripts/Floor.cs.meta
Normal file
12
Assets/Scripts/Floor.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 02652121580aeae49b2763bdc924ad87
|
||||||
|
timeCreated: 1440233203
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Scripts/IMomObserver.cs
Normal file
8
Assets/Scripts/IMomObserver.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public interface IMomObserver
|
||||||
|
{
|
||||||
|
void NotifyWarning();
|
||||||
|
void Notify();
|
||||||
|
}
|
||||||
12
Assets/Scripts/IMomObserver.cs.meta
Normal file
12
Assets/Scripts/IMomObserver.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b12285e2e2df80d409ada81aa2ba22be
|
||||||
|
timeCreated: 1440233305
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1,24 +1,35 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
|
||||||
public class MomBehavior : MonoBehaviour
|
public class MomBehavior : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Child[] Children;
|
public Action OnWarning;
|
||||||
|
public Action OnEnterRoom;
|
||||||
|
public Action OnLeaveRoom;
|
||||||
|
|
||||||
public Text WarningText;
|
public Text WarningText;
|
||||||
public float MinTriggerTime = 60f;
|
public float MinTriggerTime = 60f;
|
||||||
public float MaxTriggerTime = 90f;
|
public float MaxTriggerTime = 90f;
|
||||||
public float WarningHeadsupTime = 5f;
|
public float WarningHeadsupTime = 5f;
|
||||||
|
public float MotherStayTime = 2f;
|
||||||
|
|
||||||
private float _elapsedTime = 0f;
|
private float _elapsedTime = 0f;
|
||||||
|
|
||||||
private float _nextTriggerTime;
|
private float _nextTriggerTime;
|
||||||
|
|
||||||
|
private bool _isInRoom;
|
||||||
|
|
||||||
|
public bool IsInRoom
|
||||||
|
{
|
||||||
|
get { return _isInRoom; }
|
||||||
|
}
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_nextTriggerTime = GetNextTriggerTime();
|
_nextTriggerTime = GetNextTriggerTime();
|
||||||
Debug.Log("NextTrigger: " + _nextTriggerTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
@ -30,23 +41,39 @@ public class MomBehavior : MonoBehaviour
|
|||||||
if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime)
|
if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime)
|
||||||
{
|
{
|
||||||
WarningText.gameObject.SetActive(true);
|
WarningText.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
if (OnWarning != null)
|
||||||
|
{
|
||||||
|
OnWarning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (_elapsedTime >= _nextTriggerTime)
|
else if (_elapsedTime >= _nextTriggerTime)
|
||||||
{
|
{
|
||||||
WarningText.gameObject.SetActive(false);
|
WarningText.gameObject.SetActive(false);
|
||||||
_nextTriggerTime = GetNextTriggerTime();
|
_nextTriggerTime = GetNextTriggerTime();
|
||||||
|
|
||||||
foreach (Child child in Children)
|
|
||||||
{
|
|
||||||
if (!child.IsSleeping)
|
|
||||||
{
|
|
||||||
// TODO: Do something (end the game? kill the player? make him lose 1 life? etc.)
|
|
||||||
|
|
||||||
Debug.Log("Child " + child.Index + " got found by Mommy.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_elapsedTime = 0f;
|
_elapsedTime = 0f;
|
||||||
|
|
||||||
|
StartCoroutine(StayInRoom());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator StayInRoom()
|
||||||
|
{
|
||||||
|
if (OnEnterRoom != null)
|
||||||
|
{
|
||||||
|
OnEnterRoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
_isInRoom = true;
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(MotherStayTime);
|
||||||
|
|
||||||
|
_isInRoom = false;
|
||||||
|
|
||||||
|
if (OnLeaveRoom != null)
|
||||||
|
{
|
||||||
|
OnLeaveRoom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user