Added the Respawn Manager which allows for the use of multiple safe zones. Cleeaned up the code and made more efficient.

This commit is contained in:
Programmer-DField 2021-02-15 13:14:42 +00:00
parent 3b9e31a4b3
commit adb0c9e673
5 changed files with 240 additions and 37 deletions

View File

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RespawnManager : MonoBehaviour
{
private Vector3 respawnPoint;
public void setRespawnPoint(Vector3 _respawnPoint)
{
respawnPoint = _respawnPoint;
}
public Vector3 getRespawnPoint()
{
return respawnPoint;
}
private void Update()
{
Debug.Log(respawnPoint);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a7f7dc8ddb842944abcbcbb1d4995f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -223,6 +223,62 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!1 &254941226
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 254941229}
- component: {fileID: 254941228}
- component: {fileID: 254941227}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &254941227
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 254941226}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4a7f7dc8ddb842944abcbcbb1d4995f5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &254941228
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 254941226}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4a7f7dc8ddb842944abcbcbb1d4995f5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &254941229
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 254941226}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 17
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &258328461 --- !u!1 &258328461
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1271,6 +1327,130 @@ MonoBehaviour:
- {fileID: 597246037} - {fileID: 597246037}
- {fileID: 1381952761} - {fileID: 1381952761}
- {fileID: 1708315762} - {fileID: 1708315762}
--- !u!1 &628109597
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 628109603}
- component: {fileID: 628109602}
- component: {fileID: 628109601}
- component: {fileID: 628109600}
- component: {fileID: 628109599}
- component: {fileID: 628109598}
m_Layer: 0
m_Name: SafeZone (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &628109598
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 45048530c51ef5e4196d4fa70972441c, type: 3}
m_Name:
m_EditorClassIdentifier:
_respawnManager: {fileID: 254941228}
--- !u!65 &628109599
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 10, y: 2.220446e-16, z: 10}
m_Center: {x: 0, y: 0, z: 0}
--- !u!64 &628109600
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 4
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &628109601
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: c7c9da98e081aaa43883652afefc74b3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &628109602
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &628109603
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 628109597}
m_LocalRotation: {x: -0, y: 0.70394546, z: -0, w: 0.7102541}
m_LocalPosition: {x: 925.46, y: 518.74, z: -11.07}
m_LocalScale: {x: 0.32437897, y: 1.6604103, z: 1.6020799}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 16
m_LocalEulerAnglesHint: {x: 0, y: 89.489, z: 0}
--- !u!1 &634356289 --- !u!1 &634356289
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1696,10 +1876,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5f1d0f28dfb6a7245ac9ab4193aaed55, type: 3} m_Script: {fileID: 11500000, guid: 5f1d0f28dfb6a7245ac9ab4193aaed55, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
sz: {fileID: 971403629}
animator: {fileID: 597246038} animator: {fileID: 597246038}
fadeScreen: {fileID: 2047982323} fadeScreen: {fileID: 2047982323}
player: {fileID: 597246037} respawnManager: {fileID: 254941228}
--- !u!65 &861196245 --- !u!65 &861196245
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1835,8 +2014,8 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 971403624} m_GameObject: {fileID: 971403624}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 958.13, y: 518.5, z: -0.11} m_LocalPosition: {x: 958.13, y: 518.74, z: -1.33}
m_LocalScale: {x: 1.0044247, y: 5.141385, z: 4.9607673} m_LocalScale: {x: 0.91052103, y: 5.141385, z: 4.6924133}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 12 m_RootOrder: 12
@ -1853,9 +2032,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 45048530c51ef5e4196d4fa70972441c, type: 3} m_Script: {fileID: 11500000, guid: 45048530c51ef5e4196d4fa70972441c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
respawnPoint: {x: 0, y: 0, z: 0} _respawnManager: {fileID: 254941228}
playerPos: {x: 0, y: 0, z: 0}
lastPlayerPos: []
--- !u!65 &971403630 --- !u!65 &971403630
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -8,39 +8,35 @@ public class SafeZone : MonoBehaviour
private GameObject player; private GameObject player;
private bool isSafe = false; private bool isSafe = false;
public Vector3 respawnPoint; [SerializeField] private RespawnManager _respawnManager;
public Vector3 playerPos;
public List<Vector3> lastPlayerPos = new List<Vector3>();
private void Start()
{
player = GameObject.Find("Player");
}
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
isSafe = true; if (other.gameObject.name == "Player")
{
isSafe = true;
player = other.gameObject;
}
} }
private void OnTriggerExit(Collider other) private void OnTriggerExit(Collider other)
{ {
isSafe = false; if (other.gameObject.name == "Player")
{
isSafe = false;
}
} }
private void FixedUpdate() private void FixedUpdate()
{ {
if (isSafe == true) if (isSafe)
{ {
playerPos = player.transform.position; SetRespawnPoint(player.transform.position);
lastPlayerPos.Add(playerPos);
respawnPoint = lastPlayerPos.Last();
Debug.Log("Player Position: X = " + playerPos.x + " --- Y = " + playerPos.y + " --- Z = " + playerPos.z + " --- RespawnPoint = " + respawnPoint);
} }
} }
public Vector3 safeSpawn() private void SetRespawnPoint(Vector3 _respawnPoint)
{ {
return respawnPoint; _respawnManager.setRespawnPoint(_respawnPoint);
} }
} }

View File

@ -4,21 +4,18 @@ using UnityEngine;
public class DeathZone : MonoBehaviour public class DeathZone : MonoBehaviour
{ {
public SafeZone sz;
public Animator animator; public Animator animator;
public GameObject fadeScreen; public GameObject fadeScreen;
[SerializeField] private Transform player; private GameObject player;
private bool isDead;
[SerializeField] private RespawnManager respawnManager;
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
isDead = true; if (other.gameObject.name == "Player")
if (isDead == true)
{ {
player = other.gameObject;
StartCoroutine(respawnPlayer()); StartCoroutine(respawnPlayer());
} }
} }
@ -31,11 +28,10 @@ public class DeathZone : MonoBehaviour
fadeScreen.GetComponent<Animation>().Play("fadeAnim"); fadeScreen.GetComponent<Animation>().Play("fadeAnim");
//yield return new WaitForSeconds(0.5f); //yield return new WaitForSeconds(0.5f);
player.transform.position = sz.safeSpawn(); player.transform.position = respawnManager.getRespawnPoint();
yield return new WaitForSeconds(2); yield return new WaitForSeconds(2);
fadeScreen.GetComponent<Animation>().Play("fadeInAnim"); fadeScreen.GetComponent<Animation>().Play("fadeInAnim");
yield return null; yield return null;
isDead = false;
} }
} }