using System.Collections; using System.Collections.Generic; using UnityEngine; public class ArrowBehavior : MonoBehaviour { private static GamingManager _gamingManager; private bool bUsePhysics; private Vector3 Direction_Kinematic; private float Speed_Kinematic; private float Lifetime = 0.0f; private const float LifetimeLimit = 15f; private const float MissShootTime = 3f; private bool bHit = false; public delegate void MissShoot(); public event MissShoot OnMissShoot; // Start is called before the first frame update void Start() { _gamingManager = GameObject.Find("GameManager").GetComponent(); } public void Init(float speed, Vector3 dir, bool use_physics) { bUsePhysics = use_physics; Rigidbody rb = gameObject.GetComponent(); if (bUsePhysics) { rb.useGravity = true; rb.isKinematic = false; rb.velocity = dir * speed; } else { rb.useGravity = false; rb.isKinematic = true; rb.velocity = Vector3.zero; Speed_Kinematic = speed; Direction_Kinematic = dir; } } // Update is called once per frame void Update() { if (!_gamingManager.IsGamePaused()) { if (!bUsePhysics) { gameObject.transform.position = gameObject.transform.position + Direction_Kinematic * Time.deltaTime * Speed_Kinematic; } Lifetime += Time.deltaTime; if (Lifetime >= MissShootTime) { if (!bHit) { OnMissShoot.Invoke(); } } if (Lifetime > LifetimeLimit) { Destroy(gameObject); } } } public void HitAFruit() { bHit = true; } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "StaticCollisionScene") { Rigidbody rb = gameObject.GetComponent(); rb.isKinematic = true; rb.velocity = Vector3.zero; } } }