revival/game/Assets/Scripts/Traps/FallingRocks.cs

34 lines
853 B
C#
Raw Normal View History

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-12 18:41:34 +01:00
playerDeath.Respawn();
}
}
}