respawn fallaway floor after a few seconds in the safe zone
This commit is contained in:
parent
fbb510e70f
commit
292ca65bb2
|
@ -0,0 +1,16 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 76553ada4233edc458c3fed9b69e128f, type: 3}
|
||||||
|
m_Name: Safe Time
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_initialValue: 0
|
||||||
|
_readOnly: 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 27c10a061baeec8469e96d4f995c1445
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -84,9 +84,9 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
speed: 10
|
speed: 10
|
||||||
fallAwayTime: 1
|
fallAwayTime: 1
|
||||||
destroyObjectTime: 0
|
|
||||||
dissolve: {fileID: 2100000, guid: 98767dd77414bad44b23ef5332c1d8f1, type: 2}
|
dissolve: {fileID: 2100000, guid: 98767dd77414bad44b23ef5332c1d8f1, type: 2}
|
||||||
_renderer: {fileID: 6378198502367496824}
|
_renderer: {fileID: 6378198502367496824}
|
||||||
|
_settings: {fileID: 11400000, guid: 36275776eda5c8249bf45e01721afe36, type: 2}
|
||||||
--- !u!54 &980120856895548943
|
--- !u!54 &980120856895548943
|
||||||
Rigidbody:
|
Rigidbody:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -124,3 +124,4 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_respawnPosition: {fileID: 11400000, guid: 20fad56702134eb469a652ba680b48b2, type: 2}
|
_respawnPosition: {fileID: 11400000, guid: 20fad56702134eb469a652ba680b48b2, type: 2}
|
||||||
|
_safeTime: {fileID: 11400000, guid: 27c10a061baeec8469e96d4f995c1445, type: 2}
|
||||||
|
|
|
@ -8,13 +8,37 @@ using Ktyl.Util;
|
||||||
public class SafeZone : MonoBehaviour
|
public class SafeZone : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private SerialVector3 _respawnPosition;
|
[SerializeField] private SerialVector3 _respawnPosition;
|
||||||
|
[SerializeField] private SerialFloat _safeTime;
|
||||||
|
|
||||||
|
private const string PLAYER = "Player";
|
||||||
|
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.CompareTag(PLAYER))
|
||||||
|
{
|
||||||
|
// start counting safe time when we enter a safe zone
|
||||||
|
_safeTime.Value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTriggerStay(Collider other)
|
private void OnTriggerStay(Collider other)
|
||||||
{
|
{
|
||||||
// Check if other game object is Player.
|
// Check if other game object is Player.
|
||||||
if (other.gameObject.CompareTag("Player"))
|
if (other.gameObject.CompareTag(PLAYER))
|
||||||
{
|
{
|
||||||
_respawnPosition.Value = other.gameObject.transform.position;
|
_respawnPosition.Value = other.gameObject.transform.position;
|
||||||
|
|
||||||
|
// TODO: does this have implications for the time freeze ability?
|
||||||
|
_safeTime.Value += Time.deltaTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTriggerExit(Collider other)
|
||||||
|
{
|
||||||
|
if (other.gameObject.CompareTag(PLAYER))
|
||||||
|
{
|
||||||
|
// reset safe time when we leave safe zone
|
||||||
|
_safeTime.Value = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using Ktyl.Util;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[RequireComponent(typeof(Rigidbody))]
|
[RequireComponent(typeof(Rigidbody))]
|
||||||
|
@ -14,9 +14,11 @@ public class FallawayFloor : MonoBehaviour
|
||||||
public Material dissolve;
|
public Material dissolve;
|
||||||
|
|
||||||
[SerializeField] private Renderer _renderer;
|
[SerializeField] private Renderer _renderer;
|
||||||
|
[SerializeField] private TrapSettings _settings;
|
||||||
|
|
||||||
private Rigidbody rb;
|
private Rigidbody rb;
|
||||||
private Vector3 initialPosition;
|
private Vector3 initialPosition;
|
||||||
|
private bool _triggered = false;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
@ -26,18 +28,30 @@ public class FallawayFloor : MonoBehaviour
|
||||||
rb = GetComponent<Rigidbody>();
|
rb = GetComponent<Rigidbody>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LateUpdate()
|
||||||
|
{
|
||||||
|
if (!_triggered) return;
|
||||||
|
|
||||||
|
if (_settings.FallawayFloor.CanRespawn)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
if (other.CompareTag("Player"))
|
if (!_triggered && other.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
// Start the Destroy floor coroutine and switch to the dissolve material.
|
|
||||||
StartCoroutine(Fall());
|
StartCoroutine(Fall());
|
||||||
_renderer.material = dissolve;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator Fall()
|
private IEnumerator Fall()
|
||||||
{
|
{
|
||||||
|
// TODO: trigger shake, maybe particle effect?
|
||||||
|
|
||||||
|
_triggered = true;
|
||||||
|
|
||||||
// wait a moment
|
// wait a moment
|
||||||
yield return new WaitForSeconds(fallAwayTime);
|
yield return new WaitForSeconds(fallAwayTime);
|
||||||
|
|
||||||
|
@ -47,6 +61,7 @@ public class FallawayFloor : MonoBehaviour
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
|
_triggered = false;
|
||||||
transform.position = initialPosition;
|
transform.position = initialPosition;
|
||||||
rb.velocity = Vector3.zero;
|
rb.velocity = Vector3.zero;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Ktyl.Util;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu(menuName = "KernelPanic/Traps/Settings")]
|
||||||
|
public class TrapSettings : ScriptableObject
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public struct FallawayFloorSettings
|
||||||
|
{
|
||||||
|
// how long it takes for falling platforms to respawn while the player is safe
|
||||||
|
[SerializeField] private SerialFloat _respawnTime;
|
||||||
|
// how long the player has currently been safe for. -1 while the player is not
|
||||||
|
// in a safe zone
|
||||||
|
[SerializeField] private SerialFloat _safeTime;
|
||||||
|
|
||||||
|
public bool CanRespawn => _safeTime > _respawnTime;
|
||||||
|
}
|
||||||
|
public FallawayFloorSettings FallawayFloor => _fallawayFloor;
|
||||||
|
[SerializeField] private FallawayFloorSettings _fallawayFloor;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 93dc605253d04fe45a05492fb3feacc2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 773d36b78cd573445ad9932b0894fd99
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 76553ada4233edc458c3fed9b69e128f, type: 3}
|
||||||
|
m_Name: Fallaway Floor Respawn Time
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_initialValue: 5
|
||||||
|
_readOnly: 1
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1d2951ab5083d4d48a319ff00a9eb8bd
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 93dc605253d04fe45a05492fb3feacc2, type: 3}
|
||||||
|
m_Name: Trap Settings
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_fallawayFloor:
|
||||||
|
_respawnTime: {fileID: 11400000, guid: 1d2951ab5083d4d48a319ff00a9eb8bd, type: 2}
|
||||||
|
_safeTime: {fileID: 11400000, guid: 27c10a061baeec8469e96d4f995c1445, type: 2}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 36275776eda5c8249bf45e01721afe36
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue