2021-02-28 01:54:20 +01:00
|
|
|
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<Rigidbody>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2021-03-12 18:41:34 +01:00
|
|
|
if (collision.gameObject.TryGetComponent(out PlayerDeath playerDeath))
|
2021-03-01 17:04:17 +01:00
|
|
|
{
|
2021-03-12 18:41:34 +01:00
|
|
|
playerDeath.Respawn();
|
2021-03-01 17:04:17 +01:00
|
|
|
}
|
2021-02-28 01:54:20 +01:00
|
|
|
}
|
|
|
|
}
|