private void TurretLookAtEnemy() { if (null != mEnemyList[0]) { CastleUtility.LookAtTarget(mTurret, mEnemyList[0].transform); } }
protected override void Attack() { GameObject attackTarget = GetAttackTarget(); if (null != attackTarget) { CastleUtility.LookAtTarget(transform, attackTarget.transform); if (CastleUtility.IsTargetInAttackRange(transform, attackTarget.transform, mAttackDistance)) { mAttack.AddTarget(attackTarget); mAttack.LaunchSkill(); mHeroState = HERO_STATE.AUTO_ATTACK; } else { // change hero state to move to target mHeroState = HERO_STATE.MOVE_TO_TARGET; } } else { mAttack.LaunchSkill(); } }
private void Init() { mTurret = transform.Find(DataConfigure.PATH_TOWER_TURRET).transform; mAudioSource = transform.GetComponent <AudioSource>(); CustomInit(); mAttackInterval = CastleUtility.CalculateIntervalBetweenAttack(mAttackRate); mAttackTimeCount = mAttackInterval; }
private void MoveToTarget() { if (IsTargetAlive(mHero)) { CastleUtility.LookAtTarget(transform, mHero); transform.Translate(Vector3.forward * mSpeed * Time.fixedDeltaTime); } else { mEnemyState = ENEMY_STATE.IDLE; } }
private void StateDiscoverHeroWork() { if (CastleUtility.IsTargetInAttackRange(transform, mHero, mAttackDistance)) { mAnimator.SetBool(DataConfigure.IS_RUN_ID, false); mEnemyState = ENEMY_STATE.ATTACK; } else { mAnimator.SetBool(DataConfigure.IS_RUN_ID, true); // move to hero MoveToTarget(); } }
private void StateAttackWork() { if (IsTargetAlive(mHero)) { if (!CastleUtility.IsTargetInAttackRange(transform, mHero, mAttackDistance)) { mEnemyState = ENEMY_STATE.DISCOVER_HERO; } Attack(); } else { mEnemyState = ENEMY_STATE.IDLE; } }
private void Init() { CustomInit(); mHP = mMaxHP; InitHPSlider(); mAttackInterval = CastleUtility.CalculateIntervalBetweenAttack(mAttackRate); mAttackedTime = Time.time - mAttackInterval; mAnimator = transform.GetComponent <Animator>(); mWayPointsTransformList = WayPoints.wayPointTransformList; mNextWayPointIndex = 0; mCastle = GetCastle(); }
private void AutoMoveToTarget() { GameObject attackTarget = GetAttackTarget(); if (null != attackTarget) { if (CastleUtility.IsTargetInAttackRange(transform, attackTarget.transform, mAttackDistance)) { mHeroState = HERO_STATE.AUTO_ATTACK; } else { // move to target Vector3 direction = attackTarget.transform.position - transform.position; Vector2 correctDirection = new Vector2(direction.x, direction.z); Move(correctDirection); } } }
private void DetectSkillRangeEnemies() { for (int i = 0; i < mEnemyList.Count; ++i) { if (CastleUtility.IsTargetInAttackRange(transform, mEnemyList[i].transform, mSelectSkill.distance)) { if (mSkill3 == mSelectSkill) { mSelectSkill.AddTarget(mEnemyList[i]); } else { Vector3 inversePos = transform.InverseTransformPoint(mEnemyList[i].transform.position); if (0 <= inversePos.z) { mSelectSkill.AddTarget(mEnemyList[i]); } } } } }
private void StateMoveToCastleWork() { mAnimator.SetBool(DataConfigure.IS_RUN_ID, true); if (mWayPointsTransformList.Count <= mNextWayPointIndex) { mEnemyState = ENEMY_STATE.IDLE; } else { Vector3 nextWayPointPosition = mWayPointsTransformList[mNextWayPointIndex].position; Vector3 nextWayPointPositionIgnoreYAxis = new Vector3(nextWayPointPosition.x, 0, nextWayPointPosition.z); Vector3 currentPositionIgnoreYAxis = new Vector3(transform.position.x, 0, transform.position.z); float distanceOfNextPoint = Vector3.Distance(currentPositionIgnoreYAxis, nextWayPointPositionIgnoreYAxis); if (distanceOfNextPoint < 0.1f) { ++mNextWayPointIndex; } CastleUtility.LookAtTarget(transform, mWayPointsTransformList[mNextWayPointIndex]); transform.Translate(Vector3.forward * mSpeed * Time.deltaTime); } }