| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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<GamingManager>();
- }
- public void Init(float speed, Vector3 dir, bool use_physics)
- {
- bUsePhysics = use_physics;
- Rigidbody rb = gameObject.GetComponent<Rigidbody>();
- 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<Rigidbody>();
- rb.isKinematic = true;
- rb.velocity = Vector3.zero;
- }
- }
- }
|