using System.Collections; using System.Collections.Generic; using UnityEngine; public class FallingRocks : MonoBehaviour { Rigidbody rb; public float speed; [SerializeField] private DeathZone _dz; private void Start() { rb = GetComponent(); } // Use OnTrigger to make the "rocks" fall to the ground. Rate of fall can be controlled with speed variable. private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { rb.velocity = Vector3.down * speed; } } // Use OnCollison to call respawn method from DeathZone script. private void OnCollisionEnter(Collision collision) { // Check code is working in log. Can be deleted at a later stage. Debug.Log("Dead"); // Call respawn coroutine from DeathZone script. StartCoroutine(_dz.RespawnPlayer()); } }