| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.InputSystem;
- public enum Trans_AssassinState
- {
- None = -1,
- Normal = 0, //正常状态
- ReadyToRush = 1, //准备冲刺状态
- Rush = 2, //冲刺状态
- HaveRush = 3, //已冲刺一次状态
- ReadyToSecondRush = 4, //第二次准备冲刺状态
- SecondRush = 5, //第二次冲刺
- }
- public class Trans_Assassin : MonoBehaviour
- {
- public PlayerController player;
- public float criticalChance; //暴击率
- public float criticalMultiplier; //暴击倍数
- [HideInInspector]
- public float distance;
- public float rushSpeed;
- public float rushTime;
- public GameObject aimEffect;
- public DashEffect dashEffect;
- [HideInInspector]
- public Vector3 targetDir;
- [HideInInspector]
- public float time;
- public float nextRushTime;
- public Trans_AssassinState state;
- // Start is called before the first frame update
- void Start()
- {
- player = GetComponentInParent<PlayerController>();
- player.jumpNumber = 3;
- player.criticalChance = criticalChance;
- player.criticalMultiplier = criticalMultiplier;
- distance = rushSpeed * rushTime/2;
- }
- // Update is called once per frame
- void Update()
- {
- switch (state)
- {
- case Trans_AssassinState.Normal:
- if (player.isUltimate)
- {
- player.isUltimate = false;
- player.moveVec = player.leftDir;
- player.canMove = false;
- player.ChangeState(CharacterState.None);
- player.ani.Play("charge", 0, 0);
- player.canfly = true;
- if (!player.foot.TrigGround)
- {
- player.rb.velocity = Vector3.zero;
- player.rb.useGravity = false;
- }
- aimEffect.SetActive(true);
- aimEffect.transform.localScale =
- new Vector3(distance, 3, 1);
- state = Trans_AssassinState.ReadyToRush;
- }
- break;
- case Trans_AssassinState.ReadyToRush:
- ReadyToDash(player.moveVec);
- if (player.keyTransfigurateRelease)
- {
- player.keyTransfigurateRelease = false;
- state = Trans_AssassinState.Rush;
- time = 0;
- }
- break;
- case Trans_AssassinState.Rush:
- dashEffect.canHit = true;
- aimEffect.SetActive(false);
- player.ani.Play("attack_summon", 0, 0);
- Rush();
- time += Time.deltaTime;
- if (time >= rushTime)
- {
- player.canMove = true;
- player.canfly = false;
- dashEffect.canHit = false;
- player.bodyTrans.rotation = Quaternion.Euler(Vector3.zero);
- player.ChangeState(CharacterState.Fall);
- time = 0;
- state = Trans_AssassinState.HaveRush;
- }
- break;
- case Trans_AssassinState.HaveRush:
- time += Time.deltaTime;
- if (time >= nextRushTime)
- {
- player.EndTransfiguration(4);
- break;
- }
- if (player.isUltimate)
- {
- player.isUltimate = false;
- time = 0;
- player.moveVec = player.leftDir;
- player.canMove = false;
- player.ChangeState(CharacterState.None);
- player.ani.Play("charge", 0, 0);
- player.canfly = true;
- if (!player.foot.TrigGround)
- {
- player.rb.velocity = Vector3.zero;
- player.rb.useGravity = false;
- }
- aimEffect.SetActive(true);
- aimEffect.transform.localScale =
- new Vector3(distance, 3, 1);
- state = Trans_AssassinState.ReadyToSecondRush;
- }
- break;
- case Trans_AssassinState.ReadyToSecondRush:
- ReadyToDash(player.moveVec);
- if (player.keyTransfigurateRelease)
- {
- player.keyTransfigurateRelease = false;
- state = Trans_AssassinState.SecondRush;
- time = 0;
- }
- break;
- case Trans_AssassinState.SecondRush:
- dashEffect.canHit = true;
- aimEffect.SetActive(false);
- player.ani.Play("attack_summon", 0, 0);
- Rush();
- time += Time.deltaTime;
- if (time >= rushTime)
- {
- player.canMove = true;
- player.canfly = false;
- dashEffect.canHit = false;
- player.bodyTrans.rotation = Quaternion.Euler(Vector3.zero);
- player.ChangeState(CharacterState.Fall);
- time = 0;
- player.EndTransfiguration(4);
- }
- break;
- }
- }
- private void OnDisable()
- {
- player.criticalChance = 0;
- player.jumpNumber = 2;
- player.bodyTrans.transform.localScale = transform.GetChild(0).localScale;
- }
- public void ReadyToDash(Vector2 leftDir)
- {
- if(leftDir == Vector2.zero)
- {
- if (targetDir == Vector3.zero)
- {
- if (transform.GetChild(0).localScale.x < 0)
- {
- targetDir = Vector3.right;
- }
- else
- {
- targetDir = Vector3.left;
- }
- }
- }
- else
- {
- targetDir = leftDir.normalized;
- }
- float k = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg;
- if (targetDir.x < 0)
- {
- aimEffect.transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
- //if (!player.foot.TrigGround)
- //{
- // transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
- //}
- if (player.bodyTrans.localScale.x < 0)
- {
- player.bodyTrans.localScale =
- new Vector3(-player.bodyTrans.localScale.x,player.bodyTrans.localScale.y,
- player.bodyTrans.localScale.z);
- }
- }
- else
- {
- aimEffect.transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
- //if (!player.foot.TrigGround)
- //{
- // transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
- //}
- if (player.bodyTrans.localScale.x > 0)
- {
- player.bodyTrans.localScale =
- new Vector3(-player.bodyTrans.localScale.x,player.bodyTrans.localScale.y,
- player.bodyTrans.localScale.z);
- }
- }
- }
- private void Rush()
- {
- float k = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg;
- if (targetDir.x < 0)
- {
- dashEffect.offset = 1;
- if (player.bodyTrans.localScale.x < 0)
- {
- player.bodyTrans.localScale =
- new Vector3(-player.bodyTrans.localScale.x, player.bodyTrans.localScale.y,
- player.bodyTrans.localScale.z);
- }
- player.bodyTrans.rotation = Quaternion.Euler(new Vector3(0, 0, k - 180));
- }
- else
- {
- if (player.bodyTrans.localScale.x > 0)
- {
- player.bodyTrans.localScale =
- new Vector3(-player.bodyTrans.localScale.x, player.bodyTrans.localScale.y,
- player.bodyTrans.localScale.z);
- }
- dashEffect.offset = -1;
- player.bodyTrans.rotation = Quaternion.Euler(new Vector3(0, 0, k));
- }
- player.rb.velocity = targetDir * rushSpeed;
- }
- }
|