From 7c56c0defa7377f408f158ad6af641c35b997db4 Mon Sep 17 00:00:00 2001 From: Programmer-DField Date: Fri, 12 Mar 2021 15:58:18 +0000 Subject: [PATCH] Changes made as suggested in code review (part2) --- game/Assets/Scenes/Main.unity | 61 ++++++++++--------- game/Assets/Scripts/ArrowWall/Arrow.cs | 3 +- game/Assets/Scripts/Checkpoint/SafeZone.cs | 2 +- .../Scripts/Death & Respawn/DeathZone.cs | 14 ++--- .../Scripts/Death & Respawn/PlayerDeath.cs | 7 ++- 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/game/Assets/Scenes/Main.unity b/game/Assets/Scenes/Main.unity index a752d2f..6d518d9 100644 --- a/game/Assets/Scenes/Main.unity +++ b/game/Assets/Scenes/Main.unity @@ -140,31 +140,31 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.1208261 + value: 0.120826095 objectReference: {fileID: 0} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: -0.000000036106464 + value: 5.854628e-16 objectReference: {fileID: 0} - target: {fileID: 4676633831318799747, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: 0.0000000043948005 + value: -3.9541625e-17 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.w - value: 0.9907843 + value: 0.9907814 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.1205961 + value: 0.120595776 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: 0.061217826 + value: 0.061263908 objectReference: {fileID: 0} - target: {fileID: 4676633831388223341, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: -0.0074513005 + value: -0.0074569103 objectReference: {fileID: 0} - target: {fileID: 4676633831414007564, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_Name @@ -220,27 +220,27 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalPosition.y - value: -0.04899299 + value: 0.5793742 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalPosition.z - value: 0.007368088 + value: -0.05608368 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.w - value: 0.9935528 + value: 0.97916543 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.11337071 + value: 0.2030643 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: 0.00000002873854 + value: -0.0000000033519971 objectReference: {fileID: 0} - target: {fileID: 4676633832789495666, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: -0.0000000032792506 + value: 6.9515427e-10 objectReference: {fileID: 0} - target: {fileID: 4676633832858914730, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_XAxis.m_InvertInput @@ -252,20 +252,36 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.w - value: 0.9907843 + value: 0.9907814 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.x - value: 0.120596126 + value: 0.12059577 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.y - value: 0.06121782 + value: 0.061263897 objectReference: {fileID: 0} - target: {fileID: 4676633832928372887, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} propertyPath: m_LocalRotation.z - value: -0.007451302 + value: -0.007456909 objectReference: {fileID: 0} + - target: {fileID: 8246265507772854771, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: animator + value: + objectReference: {fileID: 1052215608} + - target: {fileID: 8246265507772854771, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: _playerDeath + value: + objectReference: {fileID: 11400000, guid: 22fd384aef0d08146831d35c2ab7f983, type: 2} + - target: {fileID: 8246265507772854771, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: _playerRespawn + value: + objectReference: {fileID: 11400000, guid: 6e31084a96bb93a44a85563a6208d0da, type: 2} + - target: {fileID: 8246265507772854771, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} + propertyPath: _respawnPosition + value: + objectReference: {fileID: 11400000, guid: 20fad56702134eb469a652ba680b48b2, type: 2} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 8a918f60d084fbe468bf3b2c0a14fb52, type: 3} --- !u!1 &59318655 @@ -493,7 +509,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: 1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &242293695 BoxCollider: m_ObjectHideFlags: 0 @@ -763,7 +778,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: -1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &412604039 BoxCollider: m_ObjectHideFlags: 0 @@ -1291,7 +1305,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: 1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &897198734 BoxCollider: m_ObjectHideFlags: 0 @@ -1740,11 +1753,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f1d0f28dfb6a7245ac9ab4193aaed55, type: 3} m_Name: m_EditorClassIdentifier: - animator: {fileID: 1052215608} - fadeScreen: {fileID: 0} - _respawnPosition: {fileID: 11400000, guid: 20fad56702134eb469a652ba680b48b2, type: 2} - _playerDeath: {fileID: 11400000, guid: 22fd384aef0d08146831d35c2ab7f983, type: 2} - _playerRespawn: {fileID: 11400000, guid: 6e31084a96bb93a44a85563a6208d0da, type: 2} --- !u!1 &1191416068 GameObject: m_ObjectHideFlags: 0 @@ -2188,7 +2196,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: -1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &1492009516 BoxCollider: m_ObjectHideFlags: 0 @@ -2380,7 +2387,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: -1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &1549198535 BoxCollider: m_ObjectHideFlags: 0 @@ -2811,7 +2817,6 @@ MonoBehaviour: speed: 4 waitToDestroy: 3 direction: {x: 1, y: 0, z: 0} - dz: {fileID: 1148358023} --- !u!65 &1875917607 BoxCollider: m_ObjectHideFlags: 0 diff --git a/game/Assets/Scripts/ArrowWall/Arrow.cs b/game/Assets/Scripts/ArrowWall/Arrow.cs index 164228f..bcfec99 100644 --- a/game/Assets/Scripts/ArrowWall/Arrow.cs +++ b/game/Assets/Scripts/ArrowWall/Arrow.cs @@ -11,7 +11,6 @@ public class Arrow : MonoBehaviour [SerializeField] private float waitToDestroy; // Vector3 to set direction of travel for the arrow once the trigger is activated. [SerializeField] private Vector3 direction; - [SerializeField] private PlayerDeath pd; private void Start() { @@ -32,7 +31,7 @@ public class Arrow : MonoBehaviour if (collision.gameObject.TryGetComponent(out PlayerDeath playerDeath)) { // Start Respawn coroutine. - StartCoroutine(pd.RespawnPlayer()); + playerDeath.Respawn(); // Destroy arrow on contact with player. Destroy(gameObject); } diff --git a/game/Assets/Scripts/Checkpoint/SafeZone.cs b/game/Assets/Scripts/Checkpoint/SafeZone.cs index ee3575d..a83e92d 100644 --- a/game/Assets/Scripts/Checkpoint/SafeZone.cs +++ b/game/Assets/Scripts/Checkpoint/SafeZone.cs @@ -17,4 +17,4 @@ public class SafeZone : MonoBehaviour _respawnPosition.Value = other.gameObject.transform.position; } } -} +} \ No newline at end of file diff --git a/game/Assets/Scripts/Death & Respawn/DeathZone.cs b/game/Assets/Scripts/Death & Respawn/DeathZone.cs index acfdcf9..ae2fdf8 100644 --- a/game/Assets/Scripts/Death & Respawn/DeathZone.cs +++ b/game/Assets/Scripts/Death & Respawn/DeathZone.cs @@ -1,19 +1,13 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using Ktyl.Util; using UnityEngine; -using UnityEngine.InputSystem; + public class DeathZone : MonoBehaviour { - [SerializeField] private PlayerDeath pd; - - private void OnTriggerEnter(Collider other) + private void OnCollisionEnter(Collision collision) { // Checks to make sure other collider is the Player. Sets player variable as Player game object and starts the coroutine. - if (other.gameObject.CompareTag("Player")) + if (collision.gameObject.TryGetComponent(out PlayerDeath playerDeath)) { - StartCoroutine(pd.RespawnPlayer()); + playerDeath.Respawn(); } } } \ No newline at end of file diff --git a/game/Assets/Scripts/Death & Respawn/PlayerDeath.cs b/game/Assets/Scripts/Death & Respawn/PlayerDeath.cs index e0f0a51..bce984b 100644 --- a/game/Assets/Scripts/Death & Respawn/PlayerDeath.cs +++ b/game/Assets/Scripts/Death & Respawn/PlayerDeath.cs @@ -14,9 +14,14 @@ public class PlayerDeath : MonoBehaviour [SerializeField] private GameEvent _playerDeath; [SerializeField] private GameEvent _playerRespawn; + public void Respawn() + { + StartCoroutine(RespawnPlayerCR()); + } + // Corountine to trigger death animation, disable player movement, play fade, // respawn player at last safe position and then play fade in animation and re-enable player movement. - public IEnumerator RespawnPlayer() + public IEnumerator RespawnPlayerCR() { animator.SetTrigger("IsDead");