| 
									
										
										
										
											2021-02-24 23:41:33 +00:00
										 |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public class FallawayFloor : MonoBehaviour | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |     // Speed at which the object moves towards the ground. | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |     public float speed; | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |     // Time it takes for ogjecct to begin moving towards the ground. | 
					
						
							|  |  |  |     public float fallAwayTime; | 
					
						
							|  |  |  |     // Time taken for object to be destroyed. | 
					
						
							|  |  |  |     public float destroyObjectTime; | 
					
						
							| 
									
										
										
										
											2021-02-26 14:50:30 +00:00
										 |  |  |     public Material dissolve; | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |     Rigidbody rb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private void Start() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |         // Get Rigidbody component. | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |         rb = GetComponent<Rigidbody>(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private void OnTriggerEnter(Collider other) | 
					
						
							| 
									
										
										
										
											2021-02-24 23:41:33 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-02-26 14:50:30 +00:00
										 |  |  |         if (other.gameObject.CompareTag("Player")) | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |             // Start the Destroy floor coroutine and switch to the dissolve material. | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |             StartCoroutine(DestroyFloor()); | 
					
						
							| 
									
										
										
										
											2021-02-26 14:50:30 +00:00
										 |  |  |             GetComponent<Renderer>().material = dissolve; | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     IEnumerator DestroyFloor() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |         // Take fallAwayTime, speed, and destroyObjectTime from editor and apply | 
					
						
							|  |  |  |         yield return new WaitForSeconds(fallAwayTime); | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  |         rb.velocity = Vector3.down * speed; | 
					
						
							| 
									
										
										
										
											2021-03-02 19:47:28 +00:00
										 |  |  |         yield return new WaitForSeconds(destroyObjectTime); | 
					
						
							| 
									
										
										
										
											2021-02-25 00:51:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         Destroy(gameObject); | 
					
						
							| 
									
										
										
										
											2021-02-24 23:41:33 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |