2021-04-15 21:31:09 +02:00
|
|
|
using Ktyl.Util;
|
2021-03-17 21:50:08 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class RollingBoulder : MonoBehaviour
|
|
|
|
{
|
2021-03-17 23:07:33 +01:00
|
|
|
Rigidbody rb;
|
|
|
|
// Float for time in seconds to wait to destroy the arrow on contact with any other gameobject that is no the player.
|
|
|
|
[SerializeField] private float waitToDestroy;
|
|
|
|
|
|
|
|
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"))
|
|
|
|
{
|
2021-03-18 13:34:08 +01:00
|
|
|
Mover mover =
|
|
|
|
gameObject.GetComponent<Mover>();
|
|
|
|
mover.enabled = true;
|
2021-04-15 21:31:09 +02:00
|
|
|
StartCoroutine(DestoryBoulder());
|
2021-03-17 23:07:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
2021-03-17 21:50:08 +01:00
|
|
|
{
|
2021-03-17 23:07:33 +01:00
|
|
|
if (collision.gameObject.TryGetComponent(out PlayerDeath playerDeath))
|
|
|
|
{
|
|
|
|
// Start Respawn coroutine.
|
|
|
|
playerDeath.Respawn();
|
|
|
|
// Destroy arrow on contact with player.
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
2021-04-15 21:31:09 +02:00
|
|
|
/*
|
2021-03-17 23:07:33 +01:00
|
|
|
else
|
|
|
|
{
|
2021-03-18 13:48:09 +01:00
|
|
|
// If boulder makes contact with any other gameobject start DestroyBoulder corountine.
|
2021-03-17 23:07:33 +01:00
|
|
|
StartCoroutine(DestoryBoulder());
|
|
|
|
}
|
2021-04-15 21:31:09 +02:00
|
|
|
*/
|
2021-03-17 21:50:08 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 23:07:33 +01:00
|
|
|
public IEnumerator DestoryBoulder()
|
2021-03-17 21:50:08 +01:00
|
|
|
{
|
2021-03-17 23:07:33 +01:00
|
|
|
// set boulder velocity to zero wait for destory time and then destory the boulder.
|
|
|
|
rb.velocity = Vector3.zero;
|
|
|
|
yield return new WaitForSeconds(waitToDestroy);
|
|
|
|
Destroy(gameObject);
|
2021-03-17 21:50:08 +01:00
|
|
|
}
|
|
|
|
}
|