Added the Arrow wall functionality. The arrow will fire in a specified direction at a specified speed. The arrow will destory itself on contact with the player immediately and after a specified time when colliding with any other game object (to give the effect the arrow is stuck in the wall). If the arrow collides with the player they will die, and be respawned at the last safe position.

This commit is contained in:
Programmer-DField 2021-03-04 23:31:22 +00:00
parent b6888e891c
commit 1a47208d3f
5 changed files with 1466 additions and 14 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4cc71201ee62efb488f75c38d71a1bba
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Arrow : MonoBehaviour
{
Rigidbody rb;
// Float for speed of the arrow.
public float speed;
// Float for time in seconds to wait to destroy the arrow on contact with any other gameobject that is no the player.
public float waitToDestroy;
// Vector3 to set direction of travel for the arrow once the trigger is activated.
public Vector3 direction;
[SerializeField] private DeathZone dz;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void OnTriggerEnter(Collider other)
{
// Checks to make sure other collider is the Player using tag.
if (other.gameObject.CompareTag("Player"))
{
rb.velocity = direction * speed;
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Player"))
{
// Start Respawn coroutine.
StartCoroutine(dz.RespawnPlayer());
// Destroy arrow on contact with player.
Destroy(gameObject);
}
else
{
// If arrow makes contact with any other gameobject start DestroyArrow corountine.
StartCoroutine(DestoryArrow());
}
}
public IEnumerator DestoryArrow()
{
// set arrow velocity to zero wait for destory time and then destory the arrow.
rb.velocity = Vector3.zero;
yield return new WaitForSeconds(waitToDestroy);
Destroy(gameObject);
}
}

View File

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

View File

@ -26,7 +26,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");