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:
parent
b6888e891c
commit
1a47208d3f
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4cc71201ee62efb488f75c38d71a1bba
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ba21ce2fa4afd344ea4d6e0cc7932d32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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.
|
||||
IEnumerator RespawnPlayer()
|
||||
public IEnumerator RespawnPlayer()
|
||||
{
|
||||
animator.SetTrigger("IsDead");
|
||||
|
||||
|
|
Loading…
Reference in New Issue