using System.Collections; using System.Collections.Generic; using UnityEngine; public class Arrow : MonoBehaviour { private float MAX_TIME = 0.8f; [SerializeField] float mSpeed = 50; [SerializeField] GameObject mPfbExplode; [SerializeField] AudioClip mShootSound; [SerializeField] AudioClip mHitSound; private GroupType mMasterGroup; private int mAtkVal; private Transform mTrans; //for curve private float mTimer = 0f; private Vector3 mInitPos = Vector3.zero; private Vector3 mTargetPos = Vector3.zero; private Vector3 mDirection = Vector3.zero; private Vector3 mHand1 = Vector3.zero; private Vector3 mHand2 = Vector3.zero; private WarUnit mTarget = null; private bool mIsActive = false; private void Awake() { mTrans = transform; } private void Update() { if (!mIsActive) return; mTrans.position += Time.deltaTime * mSpeed * mDirection; mTimer -= Time.deltaTime; if (mTimer <= 0) { Hit(); } //mTimer += Time.deltaTime; //if (mTimer <= MAX_TIME) //{ // mTrans.position = CurvePos(); //} //else if (mTimer > MAX_TIME * 2f) //{ // Destroy(gameObject); //} } public void Init(GroupType pGroup, int pAtkVal, Vector3 pInitPos, Vector3 pTargetPos, WarUnit pTarget) { mMasterGroup = pGroup; mAtkVal = pAtkVal; mInitPos = pInitPos; mTargetPos = pTargetPos; mTargetPos.y = pTarget.transform.position.y + 1; mTrans.position = mInitPos; Vector3 v = mTargetPos - mInitPos; //mHand1 = mInitPos + v * 0.4f + Vector3.up * v.magnitude / 3f; //mHand2 = mInitPos + v * 0.6f + Vector3.up * v.magnitude / 3f; //mTimer = 0; mDirection = v.normalized; mTrans.LookAt(mTargetPos); mTimer = v.magnitude / mSpeed; mTarget = pTarget; AudioManager.Instance.PlaySound(mShootSound, 0.6f); mIsActive = true; } private Vector3 CurvePos() { float t = mTimer / MAX_TIME; Vector3 tPos = Vector3.zero; tPos = (1 - t) * (1 - t) * (1 - t) * mInitPos; tPos += 3 * (1 - t) * (1 - t) * t * mHand1; tPos += 3 * (1 - t) * t * t * mHand2; tPos += t * t * t * mTargetPos; return tPos; } private void Hit() { if (mPfbExplode != null) { Instantiate(mPfbExplode, mTargetPos, Quaternion.identity); } AudioManager.Instance.PlaySound(mHitSound, 0.6f); mIsActive = false; mTarget.Hurt(mAtkVal); Destroy(gameObject); } //private void OnTriggerEnter(Collider pOther) //{ // WarUnit tUnit = pOther.GetComponent(); // if (tUnit != null && mMasterGroup != tUnit.Group) // { // tUnit.Hurt(mAtkVal); // Destroy(gameObject); // } //} }