Made changes as per code review.
This commit is contained in:
parent
1a47208d3f
commit
baad3163e6
|
@ -98,6 +98,7 @@ GameObject:
|
||||||
- component: {fileID: 3320306143821152633}
|
- component: {fileID: 3320306143821152633}
|
||||||
- component: {fileID: 4537570682397675320}
|
- component: {fileID: 4537570682397675320}
|
||||||
- component: {fileID: 2167937473989734407}
|
- component: {fileID: 2167937473989734407}
|
||||||
|
- component: {fileID: 3649858554990169966}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Player
|
m_Name: Player
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -371,6 +372,18 @@ MonoBehaviour:
|
||||||
m_StringArgument:
|
m_StringArgument:
|
||||||
m_BoolArgument: 1
|
m_BoolArgument: 1
|
||||||
m_CallState: 2
|
m_CallState: 2
|
||||||
|
--- !u!114 &3649858554990169966
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 13726836969441781}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bb840fd42f6526f4893e136a093cf1bd, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!1 &13726837642651461
|
--- !u!1 &13726837642651461
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5ed6528357dd2bb4c92cb1101f214604
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 55fadb9f11c9ea74fb586631ce45bd14
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -6,12 +6,12 @@ public class Arrow : MonoBehaviour
|
||||||
{
|
{
|
||||||
Rigidbody rb;
|
Rigidbody rb;
|
||||||
// Float for speed of the arrow.
|
// Float for speed of the arrow.
|
||||||
public float speed;
|
[SerializeField] private float speed;
|
||||||
// Float for time in seconds to wait to destroy the arrow on contact with any other gameobject that is no the player.
|
// Float for time in seconds to wait to destroy the arrow on contact with any other gameobject that is no the player.
|
||||||
public float waitToDestroy;
|
[SerializeField] private float waitToDestroy;
|
||||||
// Vector3 to set direction of travel for the arrow once the trigger is activated.
|
// Vector3 to set direction of travel for the arrow once the trigger is activated.
|
||||||
public Vector3 direction;
|
[SerializeField] private Vector3 direction;
|
||||||
[SerializeField] private DeathZone dz;
|
[SerializeField] private PlayerDeath pd;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
@ -29,10 +29,10 @@ public class Arrow : MonoBehaviour
|
||||||
|
|
||||||
private void OnCollisionEnter(Collision collision)
|
private void OnCollisionEnter(Collision collision)
|
||||||
{
|
{
|
||||||
if (collision.gameObject.CompareTag("Player"))
|
if (collision.gameObject.TryGetComponent(out PlayerDeath playerDeath))
|
||||||
{
|
{
|
||||||
// Start Respawn coroutine.
|
// Start Respawn coroutine.
|
||||||
StartCoroutine(dz.RespawnPlayer());
|
StartCoroutine(pd.RespawnPlayer());
|
||||||
// Destroy arrow on contact with player.
|
// Destroy arrow on contact with player.
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class SafeZone : MonoBehaviour
|
||||||
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.name == "Player")
|
if (other.gameObject.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
_respawnPosition.Value = other.gameObject.transform.position;
|
_respawnPosition.Value = other.gameObject.transform.position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,46 +5,15 @@ using Ktyl.Util;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
public class DeathZone : MonoBehaviour
|
public class DeathZone : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Animator animator;
|
[SerializeField] private PlayerDeath pd;
|
||||||
public GameObject fadeScreen;
|
|
||||||
|
|
||||||
private GameObject player;
|
|
||||||
|
|
||||||
[SerializeField] private SerialVector3 _respawnPosition;
|
|
||||||
[SerializeField] private GameEvent _playerDeath;
|
|
||||||
[SerializeField] private GameEvent _playerRespawn;
|
|
||||||
|
|
||||||
private void OnTriggerEnter(Collider other)
|
private void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
// Checks to make sure other collider is the Player. Sets player variable as Player game object and starts the coroutine.
|
// Checks to make sure other collider is the Player. Sets player variable as Player game object and starts the coroutine.
|
||||||
if (other.gameObject.name == "Player")
|
if (other.gameObject.CompareTag("Player"))
|
||||||
{
|
{
|
||||||
player = other.gameObject;
|
StartCoroutine(pd.RespawnPlayer());
|
||||||
StartCoroutine(RespawnPlayer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
animator.SetTrigger("IsDead");
|
|
||||||
|
|
||||||
_playerDeath.Raise();
|
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.5f);
|
|
||||||
|
|
||||||
fadeScreen.GetComponent<Animator>().SetTrigger("fadeToBlack");
|
|
||||||
yield return new WaitForSeconds(1.5f);
|
|
||||||
|
|
||||||
// move player to respawn position
|
|
||||||
player.transform.position = _respawnPosition;
|
|
||||||
|
|
||||||
fadeScreen.GetComponent<Animator>().SetTrigger("fadeToClear");
|
|
||||||
yield return new WaitForSeconds(0.5f);
|
|
||||||
|
|
||||||
_playerRespawn.Raise();
|
|
||||||
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Ktyl.Util;
|
||||||
|
|
||||||
|
public class PlayerDeath : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Animator animator;
|
||||||
|
public GameObject fadeScreen;
|
||||||
|
|
||||||
|
private GameObject player;
|
||||||
|
|
||||||
|
[SerializeField] private SerialVector3 _respawnPosition;
|
||||||
|
[SerializeField] private GameEvent _playerDeath;
|
||||||
|
[SerializeField] private GameEvent _playerRespawn;
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
{
|
||||||
|
animator.SetTrigger("IsDead");
|
||||||
|
|
||||||
|
_playerDeath.Raise();
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(0.5f);
|
||||||
|
|
||||||
|
fadeScreen.GetComponent<Animator>().SetTrigger("fadeToBlack");
|
||||||
|
yield return new WaitForSeconds(1.5f);
|
||||||
|
|
||||||
|
// move player to respawn position
|
||||||
|
player.transform.position = _respawnPosition;
|
||||||
|
|
||||||
|
fadeScreen.GetComponent<Animator>().SetTrigger("fadeToClear");
|
||||||
|
yield return new WaitForSeconds(0.5f);
|
||||||
|
|
||||||
|
_playerRespawn.Raise();
|
||||||
|
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bb840fd42f6526f4893e136a093cf1bd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue