Add the behavior of the floor changing color when the mom enters the room

This commit is contained in:
Patrice Vignola 2015-08-22 05:31:34 -04:00
parent 5413a3bf20
commit 098cdefe14
14 changed files with 139 additions and 13 deletions

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 17f1fb22be4247d4baff3f576a2cb9aa
timeCreated: 1440233010
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View 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

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 46cbd4a59ec21ba4d8adfffd70146cb7
timeCreated: 1440235651
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -2,12 +2,13 @@
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class Child : MonoBehaviour
public class Child : MonoBehaviour
{
public float Speed = 10f;
public float JumpForce = 10f;
public GameObject GroundCheck;
public Pillow pillow;
public MomBehavior Mom;
private Rigidbody _rb;
private bool _isGrounded = false;
@ -37,6 +38,13 @@ public class Child : MonoBehaviour
void Update()
{
_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) {

35
Assets/Scripts/Floor.cs Normal file
View 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;
}
}

View 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:

View File

@ -0,0 +1,8 @@
using UnityEngine;
using System.Collections;
public interface IMomObserver
{
void NotifyWarning();
void Notify();
}

View 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:

View File

@ -1,24 +1,35 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
public class MomBehavior : MonoBehaviour
{
public Child[] Children;
public Action OnWarning;
public Action OnEnterRoom;
public Action OnLeaveRoom;
public Text WarningText;
public float MinTriggerTime = 60f;
public float MaxTriggerTime = 90f;
public float WarningHeadsupTime = 5f;
public float MotherStayTime = 2f;
private float _elapsedTime = 0f;
private float _nextTriggerTime;
private bool _isInRoom;
public bool IsInRoom
{
get { return _isInRoom; }
}
void Awake()
{
_nextTriggerTime = GetNextTriggerTime();
Debug.Log("NextTrigger: " + _nextTriggerTime);
}
void Update()
@ -30,23 +41,39 @@ public class MomBehavior : MonoBehaviour
if (_elapsedTime >= _nextTriggerTime - WarningHeadsupTime && _elapsedTime < _nextTriggerTime)
{
WarningText.gameObject.SetActive(true);
if (OnWarning != null)
{
OnWarning();
}
}
else if (_elapsedTime >= _nextTriggerTime)
{
WarningText.gameObject.SetActive(false);
_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;
StartCoroutine(StayInRoom());
}
}
private IEnumerator StayInRoom()
{
if (OnEnterRoom != null)
{
OnEnterRoom();
}
_isInRoom = true;
yield return new WaitForSeconds(MotherStayTime);
_isInRoom = false;
if (OnLeaveRoom != null)
{
OnLeaveRoom();
}
}