Trans_Assassin.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Trans_Assassin : MonoBehaviour
  5. {
  6. public PlayerController player;
  7. public float criticalChance; //±©»÷ÂÊ
  8. public float criticalMultiplier; //±©»÷±¶Êý
  9. public bool isUltimate;
  10. public bool isNextUltimate;
  11. [HideInInspector]
  12. public float distance;
  13. public float rushSpeed;
  14. public float rushTime;
  15. public GameObject aimEffect;
  16. public DashEffect dashEffect;
  17. [HideInInspector]
  18. public Vector3 targetDir;
  19. [HideInInspector]
  20. public float time;
  21. public float nextRushTime;
  22. // Start is called before the first frame update
  23. void Start()
  24. {
  25. player = GetComponentInParent<PlayerController>();
  26. player.jumpNumber = 3;
  27. player.criticalChance = criticalChance;
  28. player.criticalMultiplier = criticalMultiplier;
  29. distance = rushSpeed * rushTime/2;
  30. }
  31. // Update is called once per frame
  32. void Update()
  33. {
  34. if (isNextUltimate)
  35. {
  36. if (isUltimate)
  37. {
  38. if (player.isUltimate)
  39. {
  40. ReadyToDash(player.moveVec);
  41. }
  42. else
  43. {
  44. dashEffect.canHit = true;
  45. aimEffect.SetActive(false);
  46. player.ani.Play("attack_summon", 0, 0);
  47. Rush();
  48. time += Time.deltaTime;
  49. if (time >= rushTime)
  50. {
  51. //isNextUltimate = true;
  52. //isUltimate = false;
  53. player.canMove = true;
  54. player.canfly = false;
  55. dashEffect.canHit = false;
  56. player.bodyTrans.rotation = Quaternion.Euler(Vector3.zero);
  57. player.ChangeState(CharacterState.Fall);
  58. time = 0;
  59. player.EndTransfiguration(4);
  60. }
  61. }
  62. }
  63. else
  64. {
  65. time += Time.deltaTime;
  66. if (time >= nextRushTime)
  67. {
  68. player.EndTransfiguration(4);
  69. }
  70. if (player.isUltimate)
  71. {
  72. time = 0;
  73. player.moveVec = player.leftDir;
  74. player.canMove = false;
  75. player.ChangeState(CharacterState.None);
  76. player.ani.Play("charge", 0, 0);
  77. player.canfly = true;
  78. if (!player.foot.TrigGround)
  79. {
  80. player.rb.velocity = Vector3.zero;
  81. player.rb.useGravity = false;
  82. }
  83. aimEffect.SetActive(true);
  84. aimEffect.transform.localScale =
  85. new Vector3(distance, 3, 1);
  86. isUltimate = true;
  87. }
  88. }
  89. }
  90. else
  91. {
  92. if (isUltimate)
  93. {
  94. if (player.isUltimate)
  95. {
  96. ReadyToDash(player.moveVec);
  97. }
  98. else
  99. {
  100. dashEffect.canHit = true;
  101. aimEffect.SetActive(false);
  102. player.ani.Play("attack_summon", 0, 0);
  103. Rush();
  104. time += Time.deltaTime;
  105. if (time >= rushTime)
  106. {
  107. isNextUltimate = true;
  108. isUltimate = false;
  109. player.canMove = true;
  110. player.canfly = false;
  111. dashEffect.canHit = false;
  112. player.bodyTrans.rotation = Quaternion.Euler(Vector3.zero);
  113. player.ChangeState(CharacterState.Fall);
  114. time = 0;
  115. }
  116. }
  117. }
  118. else
  119. {
  120. if (player.isUltimate)
  121. {
  122. player.moveVec = player.leftDir;
  123. player.canMove = false;
  124. player.ChangeState(CharacterState.None);
  125. player.ani.Play("charge", 0, 0);
  126. player.canfly = true;
  127. if (!player.foot.TrigGround)
  128. {
  129. player.rb.velocity = Vector3.zero;
  130. player.rb.useGravity = false;
  131. }
  132. aimEffect.SetActive(true);
  133. aimEffect.transform.localScale =
  134. new Vector3(distance, 3, 1);
  135. isUltimate = true;
  136. }
  137. }
  138. }
  139. }
  140. private void OnDisable()
  141. {
  142. player.criticalChance = 0;
  143. }
  144. public void ReadyToDash(Vector2 leftDir)
  145. {
  146. if(leftDir == Vector2.zero)
  147. {
  148. if (player.transform.localScale.x > 0)
  149. {
  150. targetDir = Vector3.right;
  151. }
  152. else
  153. {
  154. targetDir = Vector3.left;
  155. }
  156. }
  157. else
  158. {
  159. targetDir = leftDir.normalized;
  160. }
  161. float k = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg;
  162. if (targetDir.x < 0)
  163. {
  164. aimEffect.transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
  165. //if (!player.foot.TrigGround)
  166. //{
  167. // transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
  168. //}
  169. if (player.bodyTrans.localScale.x < 0)
  170. {
  171. player.bodyTrans.localScale =
  172. new Vector3(-player.bodyTrans.localScale.x,player.bodyTrans.localScale.y,
  173. player.bodyTrans.localScale.z);
  174. }
  175. }
  176. else
  177. {
  178. aimEffect.transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
  179. //if (!player.foot.TrigGround)
  180. //{
  181. // transform.rotation = Quaternion.Euler(new Vector3(0, 0, k));
  182. //}
  183. if (player.bodyTrans.localScale.x > 0)
  184. {
  185. player.bodyTrans.localScale =
  186. new Vector3(-player.bodyTrans.localScale.x,player.bodyTrans.localScale.y,
  187. player.bodyTrans.localScale.z);
  188. }
  189. }
  190. }
  191. private void Rush()
  192. {
  193. float k = Mathf.Atan2(targetDir.y, targetDir.x) * Mathf.Rad2Deg;
  194. if (targetDir.x < 0)
  195. {
  196. dashEffect.offset = 1;
  197. if (player.bodyTrans.localScale.x < 0)
  198. {
  199. player.bodyTrans.localScale =
  200. new Vector3(-player.bodyTrans.localScale.x, player.bodyTrans.localScale.y,
  201. player.bodyTrans.localScale.z);
  202. }
  203. player.bodyTrans.rotation = Quaternion.Euler(new Vector3(0, 0, k - 180));
  204. }
  205. else
  206. {
  207. if (player.bodyTrans.localScale.x > 0)
  208. {
  209. player.bodyTrans.localScale =
  210. new Vector3(-player.bodyTrans.localScale.x, player.bodyTrans.localScale.y,
  211. player.bodyTrans.localScale.z);
  212. }
  213. dashEffect.offset = -1;
  214. player.bodyTrans.rotation = Quaternion.Euler(new Vector3(0, 0, k));
  215. }
  216. player.rb.velocity = targetDir * rushSpeed;
  217. }
  218. }