| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public enum AssassinState
- {
- None = -1,
- Normal = 0, //正常状态
- FindPlayer = 1, //寻找主角位置
- ReadyToDash = 2, //准备攻击主角
- Dash = 3, //向主角方向冲刺
- Down = 4, //落地斩
- }
- public class ESpirits_Assassin : MonoBehaviour
- {
- [HideInInspector]
- public float time;
- public float attackCD;
- public float readyCD;
- public float hateDistance;
- public AssassinState state;
- public Enemy enemy;
- public Rigidbody rb;
- [HideInInspector]
- public float distance;
- public DashEffect dashEffect;
- public float moveSpeed;
- public float offset;
- [HideInInspector]
- public Vector3 targetDir;
- public float dashTime;
- private void Update()
- {
- OnState();
- }
- public void OnState()
- {
- switch (state)
- {
- case AssassinState.Normal:
- time += Time.deltaTime;
- if (time > attackCD)
- {
- enemy.isSpiritsAttack = true;
- time = 0;
- state = AssassinState.FindPlayer;
- ChosePlayer();
- enemy.searchState = SearchState.InSearchScope;
- enemy.ChangeState(CharacterState.Run);
- }
- break;
- case AssassinState.FindPlayer:
- ChosePlayer();
- if (distance <= hateDistance)
- {
- state = AssassinState.ReadyToDash;
- enemy.ChangeState(CharacterState.Rush);
- rb.velocity = Vector3.zero;
- enemy.ani.Play("hitted", 0, 0);
- enemy.aniCollider.Play("Hurt", 0, 0);
- }
- break;
- case AssassinState.ReadyToDash:
- time += Time.deltaTime;
- if (time >= readyCD)
- {
- state = AssassinState.Dash;
- dashEffect.isDash = true;
- dashEffect.isDashAttack = true;
- targetDir =
- (enemy.targetCharacter.transform.position - transform.position).normalized;
- enemy.ani.Play("attack_summon", 0, 0);
- time = 0;
- }
- break;
- case AssassinState.Dash:
- time += Time.deltaTime;
- Dash();
- if (time >= dashTime)
- {
- rb.velocity = Vector3.zero;
- time = 0;
- if (enemy.foot.TrigGround)
- {
- dashEffect.isDashAttack = false;
- state = AssassinState.Normal;
- enemy.isSpiritsAttack = false;
- enemy.searchState = SearchState.NoTarget;
- enemy.ChangeState(CharacterState.Idle);
- }
- else
- {
- state = AssassinState.Down;
- }
- }
- break;
- case AssassinState.Down:
- break;
- }
- }
- public void ChosePlayer()
- {
- float distance0 = 1000;
- float distance1 = 1000;
- if (PlayersInput.instance[0])
- {
- distance0 = Mathf.Abs(PlayersInput.instance[0].transform.position.x
- - transform.position.x);
- }
- if (PlayersInput.instance[1])
- {
- distance1 = Mathf.Abs(PlayersInput.instance[1].transform.position.x
- - transform.position.x);
- }
- if (distance0 <= distance1)
- {
- enemy.targetCharacter = PlayersInput.instance[0];
- distance = distance0;
-
- }
- else
- {
- enemy.targetCharacter = PlayersInput.instance[1];
- distance = distance1;
- }
- }
- private void Dash()
- {
- if (targetDir.x < 0)
- {
- dashEffect.offset = offset;
- }
- else
- {
- dashEffect.offset = -offset;
- }
- rb.velocity = targetDir * moveSpeed;
- }
- }
|