Added the falling rocks trap. The player can now trigger the rocks to fall and the death and respawn script will run when a collision is detected. Need to look at an issue where the collision is detected even when the player is not hit. Possibly the camera?

This commit is contained in:
Programmer-DField 2021-02-28 00:54:20 +00:00
parent 078e356810
commit 4bead84e56
4 changed files with 1983 additions and 107 deletions

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ public class DeathZone : MonoBehaviour
} }
// Corountine to trigger death animation, disable player movement, play fade, respawn player at last safe position and then play fade in animation and re-enable player movement. // Corountine to trigger death animation, disable player movement, play fade, respawn player at last safe position and then play fade in animation and re-enable player movement.
IEnumerator RespawnPlayer() public IEnumerator RespawnPlayer()
{ {
animator.SetTrigger("IsDead"); animator.SetTrigger("IsDead");
_playerInput.enabled = false; _playerInput.enabled = false;

View File

@ -0,0 +1,33 @@
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)
{
// 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());
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd465a93255c6bf4090c0f0a8897d07b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: