| 
									
										
										
										
											2021-03-03 12:53:52 +00:00
										 |  |  | using System; | 
					
						
							| 
									
										
										
										
											2021-02-15 09:44:04 +00:00
										 |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | using System.Linq; | 
					
						
							| 
									
										
										
										
											2021-03-03 12:53:52 +00:00
										 |  |  | using Ktyl.Util; | 
					
						
							| 
									
										
										
										
											2021-02-15 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | public class SafeZone : MonoBehaviour | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-03 12:53:52 +00:00
										 |  |  |     [SerializeField] private SerialVector3 _respawnPosition; | 
					
						
							| 
									
										
										
										
											2021-03-17 18:04:31 +00:00
										 |  |  |     [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; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-15 09:44:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 12:53:52 +00:00
										 |  |  |     private void OnTriggerStay(Collider other) | 
					
						
							| 
									
										
										
										
											2021-02-15 09:44:04 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-02-15 16:23:29 +00:00
										 |  |  |         // Check if other game object is Player. | 
					
						
							| 
									
										
										
										
											2021-03-17 18:04:31 +00:00
										 |  |  |         if (other.gameObject.CompareTag(PLAYER)) | 
					
						
							| 
									
										
										
										
											2021-02-15 13:14:42 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-03-03 12:53:52 +00:00
										 |  |  |             _respawnPosition.Value = other.gameObject.transform.position; | 
					
						
							| 
									
										
										
										
											2021-03-17 18:04:31 +00:00
										 |  |  |              | 
					
						
							|  |  |  |             // 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; | 
					
						
							| 
									
										
										
										
											2021-02-15 09:44:04 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-12 15:58:18 +00:00
										 |  |  | } |