Demonic.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. using Spine.Unity;
  2. using Spine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class Demonic : MoveCharacter
  7. {
  8. [Header("友方单位属性")]
  9. public PlayerController player; //召唤师
  10. public int playerID;
  11. public int id;
  12. public float costMp = 10;
  13. public float totalSummonTime = 0.5f;
  14. public bool isBack = false; //往反方向走
  15. public float flyHeight;
  16. public float flyUpSpeed = 10;
  17. public int baseSortingOrder;
  18. int sortingOrder = 0;
  19. public float runSpeed;
  20. [Header("锁魂塔")]
  21. public bool isReturnSoulTower;
  22. public Vector3 origSoulPos;
  23. public bool isRecorded;
  24. [Header("友方单位组件")]
  25. public SearchState searchState;
  26. public Collider soulCollector;
  27. [Header("攻击")]
  28. public float attackDistance;
  29. public float maxAttackDis, minAttackDis;
  30. public bool needToChange;
  31. [Header("八卦")]
  32. public float adsorbSpeed; //八卦吸附的速度
  33. [HideInInspector] public Vector3 adsorbTarget; //八卦胖子吸附时目标位置的X
  34. private float adsorbTime; //八卦吸附中的时间
  35. public GameObject effectPrefab; //八卦卦象效果
  36. [Header("掉落魂")]
  37. public int dropSoulMax = 3;
  38. public int dropSoulMin = 1;
  39. public float dropSoulAngle = 60f;
  40. [Header("验证功能开关")]
  41. public bool upFirstAfterWeaknessOrNot; //虚弱结束后是否先升高
  42. public bool isBeBlownUp; //被击飞
  43. private void Start()
  44. {
  45. if (needToChange)
  46. {
  47. attackDistance = Random.Range(minAttackDis, maxAttackDis);
  48. }
  49. }
  50. private void OnDisable()
  51. {
  52. PlayersInput.instance[playerID].OnDemonicRecycle(this);
  53. }
  54. public override void FixedUpdate()
  55. {
  56. if (!attackController.isNonAttack)
  57. {
  58. OnSearchState();
  59. }
  60. OnState();
  61. }
  62. public bool SearchTarget()
  63. {
  64. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, attackController.canHitFly);
  65. if (targetCharacter != null)
  66. {
  67. return true;
  68. }
  69. else
  70. {
  71. return false;
  72. }
  73. }
  74. public void ChangeSearchState(SearchState newState)
  75. {
  76. switch (searchState)
  77. {
  78. case SearchState.NoTarget:
  79. break;
  80. case SearchState.InSearchScope:
  81. break;
  82. case SearchState.InAttackScope:
  83. break;
  84. default:
  85. break;
  86. }
  87. searchState = newState;
  88. switch (searchState)
  89. {
  90. case SearchState.NoTarget:
  91. targetCharacter = null;
  92. break;
  93. case SearchState.InSearchScope:
  94. break;
  95. case SearchState.InAttackScope:
  96. break;
  97. default:
  98. break;
  99. }
  100. }
  101. public void OnSearchState()
  102. {
  103. switch (searchState)
  104. {
  105. case SearchState.NoTarget:
  106. if (SearchTarget())
  107. {
  108. ChangeSearchState(SearchState.InSearchScope);
  109. break;
  110. }
  111. //向玩家基地移动
  112. break;
  113. case SearchState.InSearchScope:
  114. if (!SearchTarget())
  115. {
  116. targetCharacter = null;
  117. ChangeSearchState(SearchState.NoTarget);
  118. break;
  119. }
  120. if (targetCharacter != null && Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) <= attackDistance)
  121. {
  122. ChangeSearchState(SearchState.InAttackScope);
  123. break;
  124. }
  125. break;
  126. case SearchState.InAttackScope:
  127. if (targetCharacter != null)
  128. {
  129. if (!targetCharacter.gameObject.activeInHierarchy || targetCharacter.isDie
  130. || Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) > attackDistance)
  131. {
  132. ChangeSearchState(SearchState.NoTarget);
  133. }
  134. }
  135. else
  136. {
  137. ChangeSearchState(SearchState.NoTarget);
  138. }
  139. break;
  140. default:
  141. break;
  142. }
  143. }
  144. public override Vector3 GetMoveDir()
  145. {
  146. Vector3 moveDir = Vector3.zero;
  147. if (canMove)
  148. {
  149. if (!isTran)
  150. {
  151. switch (searchState)
  152. {
  153. case SearchState.NoTarget:
  154. if (TowerMap.enemyTowers.Count == 0)
  155. {
  156. moveDir = Vector3.left;
  157. break;
  158. }
  159. float minDistance = Mathf.Infinity;
  160. int id = -1;
  161. for (int i = 0; i < TowerMap.enemyTowers.Count; i++)
  162. {
  163. EnemyTower enemyTower = TowerMap.enemyTowers[i].GetComponent<EnemyTower>();
  164. if (transform.position.y >
  165. enemyTower.transform.position.y + enemyTower.height)
  166. {
  167. continue;
  168. }
  169. float distance = Vector3.Distance(transform.position,
  170. TowerMap.enemyTowers[i].transform.position);
  171. if (distance < minDistance)
  172. {
  173. minDistance = distance;
  174. id = i;
  175. }
  176. }
  177. if (id == -1)
  178. {
  179. moveDir = Vector3.left;
  180. break;
  181. }
  182. if (bodyTrans.position.x > TowerMap.enemyTowers[id].transform.position.x)
  183. {
  184. moveDir = Vector3.left;
  185. }
  186. else
  187. {
  188. moveDir = Vector3.right;
  189. }
  190. break;
  191. case SearchState.InSearchScope:
  192. if (targetCharacter)
  193. {
  194. if (targetCharacter.transform.position.x - transform.position.x < 0)
  195. {
  196. moveDir = Vector3.left;
  197. }
  198. else
  199. {
  200. moveDir = Vector3.right;
  201. }
  202. }
  203. else
  204. {
  205. moveDir = Vector3.zero;
  206. }
  207. break;
  208. case SearchState.InAttackScope:
  209. if (targetCharacter)
  210. {
  211. if (targetCharacter.transform.position.x - transform.position.x < 0)
  212. {
  213. moveDir = Vector3.left;
  214. }
  215. else
  216. {
  217. moveDir = Vector3.right;
  218. }
  219. }
  220. else
  221. {
  222. moveDir = Vector3.zero;
  223. }
  224. break;
  225. default:
  226. break;
  227. }
  228. }
  229. else
  230. {
  231. if (pc == null)
  232. {
  233. pc = GetComponentInParent<PlayerController>();
  234. }
  235. moveDir = pc.GetMoveDir();
  236. }
  237. }
  238. if (!isBack)
  239. {
  240. return moveDir;
  241. }
  242. return -moveDir;
  243. }
  244. public bool GetAttack()
  245. {
  246. if (searchState == SearchState.InAttackScope)
  247. {
  248. return true;
  249. }
  250. return false;
  251. }
  252. public bool AdjustHeight()
  253. {
  254. if (canFly)
  255. {
  256. if (transform.position.y - flyHeight > 0.1f)
  257. {
  258. Vector3 pos = transform.position;
  259. pos.y -= flyUpSpeed * Time.deltaTime;
  260. transform.position = pos;
  261. return false;
  262. }
  263. else if (transform.position.y - flyHeight < -0.1f)
  264. {
  265. Vector3 pos = transform.position;
  266. pos.y += flyUpSpeed * Time.deltaTime;
  267. transform.position = pos;
  268. return false;
  269. }
  270. }
  271. return true;
  272. }
  273. public override void OnState()
  274. {
  275. base.OnState();
  276. //hurtKeepTime -= Time.deltaTime;
  277. dieKeepTime -= Time.deltaTime;
  278. invincibleTime -= Time.deltaTime;
  279. weakTime -= Time.deltaTime;
  280. beRepelValue += Time.deltaTime;
  281. Vector3 leftDir = GetMoveDir();
  282. bool isAttack = GetAttack();
  283. switch (state)
  284. {
  285. case CharacterState.Idle:
  286. if (isAttack)
  287. {
  288. Attack_march();
  289. break;
  290. }
  291. if (!foot.TrigGround && !canFly)
  292. {
  293. if (rb.velocity.y > 0)
  294. {
  295. ChangeState(CharacterState.Rise);
  296. break;
  297. }
  298. else
  299. {
  300. ChangeState(CharacterState.Fall);
  301. break;
  302. }
  303. }
  304. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  305. {
  306. ChangeState(CharacterState.Run);
  307. break;
  308. }
  309. if (!upFirstAfterWeaknessOrNot)
  310. {
  311. if (canFly)
  312. {
  313. rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
  314. rb.useGravity = false;
  315. AdjustHeight();
  316. }
  317. }
  318. rb.velocity = Vector3.right * velocityAddition;
  319. break;
  320. case CharacterState.Run:
  321. if (isAttack)
  322. {
  323. Attack_march();
  324. break;
  325. }
  326. if (!foot.TrigGround && !canFly)
  327. {
  328. if (rb.velocity.y > 0)
  329. {
  330. ChangeState(CharacterState.Rise);
  331. break;
  332. }
  333. else
  334. {
  335. ChangeState(CharacterState.Fall);
  336. break;
  337. }
  338. }
  339. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  340. {
  341. ChangeState(CharacterState.Idle);
  342. break;
  343. }
  344. if (leftDir.x > 0.3f)
  345. {
  346. //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
  347. rb.velocity = Vector3.right * (moveSpeed + velocityAddition);
  348. //if (rb.velocity.x > maxMoveSpeed)
  349. //{
  350. // rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  351. //}
  352. if (bodyTrans.localScale.x > 0)
  353. {
  354. Turn();
  355. }
  356. }
  357. else if (leftDir.x < -0.3f)
  358. {
  359. //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
  360. rb.velocity = Vector3.right * (-moveSpeed + velocityAddition);
  361. //if (rb.velocity.x < -maxMoveSpeed)
  362. //{
  363. // rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  364. //}
  365. if (bodyTrans.localScale.x < 0)
  366. {
  367. Turn();
  368. }
  369. }
  370. if (!upFirstAfterWeaknessOrNot)
  371. {
  372. if (canFly)
  373. {
  374. rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
  375. rb.useGravity = false;
  376. AdjustHeight();
  377. }
  378. }
  379. break;
  380. case CharacterState.Rush:
  381. if (isAttack)
  382. {
  383. Attack_march();
  384. break;
  385. }
  386. if (!foot.TrigGround && !canFly)
  387. {
  388. if (rb.velocity.y > 0)
  389. {
  390. ChangeState(CharacterState.Rise);
  391. break;
  392. }
  393. else
  394. {
  395. ChangeState(CharacterState.Fall);
  396. break;
  397. }
  398. }
  399. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  400. {
  401. ChangeState(CharacterState.Idle);
  402. break;
  403. }
  404. if (leftDir.x > 0.3f)
  405. {
  406. //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
  407. rb.velocity = Vector3.right * runSpeed;
  408. //if (rb.velocity.x > maxMoveSpeed)
  409. //{
  410. // rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  411. //}
  412. if (bodyTrans.localScale.x > 0)
  413. {
  414. Turn();
  415. }
  416. }
  417. else if (leftDir.x < -0.3f)
  418. {
  419. //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
  420. rb.velocity = Vector3.left * runSpeed;
  421. //if (rb.velocity.x < -maxMoveSpeed)
  422. //{
  423. // rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  424. //}
  425. if (bodyTrans.localScale.x < 0)
  426. {
  427. Turn();
  428. }
  429. }
  430. //AdjustHeight();
  431. break;
  432. case CharacterState.Rise:
  433. if (rb.velocity.y <= 0)
  434. {
  435. ChangeState(CharacterState.Fall);
  436. break;
  437. }
  438. //if (btnJumpPress || cacheJumpTime > 0)
  439. //{
  440. // if (!airJumped && rb.velocity.y < airJumpSpeed)
  441. // {
  442. // airJumped = true;
  443. // AirJump();
  444. // break;
  445. // }
  446. //}
  447. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  448. break;
  449. case CharacterState.Fall:
  450. if (foot.TrigGround || canFly)
  451. {
  452. ChangeState(CharacterState.Idle);
  453. break;
  454. }
  455. Vector3 velocity = rb.velocity;
  456. velocity.y += extraFallGravity * Time.deltaTime;
  457. if (leftDir.x > 0.3f)
  458. {
  459. velocity.x = moveSpeed;
  460. if (bodyTrans.localScale.x > 0)
  461. {
  462. Turn();
  463. }
  464. }
  465. else if (leftDir.x < -0.3f)
  466. {
  467. velocity.x = -moveSpeed;
  468. if (bodyTrans.localScale.x < 0)
  469. {
  470. Turn();
  471. }
  472. }
  473. rb.velocity = velocity;
  474. break;
  475. case CharacterState.Coma:
  476. pastComaTime += Time.deltaTime;
  477. if (pastComaTime >= comaTime)
  478. {
  479. ChangeState(CharacterState.Idle);
  480. }
  481. break;
  482. case CharacterState.Attack:
  483. attackController.attackTime -= Time.deltaTime;
  484. attackController.attackKeyCount += Time.deltaTime;
  485. if (!attackController.isAttackTriggerOn && attackController.attackKeyCount >=
  486. attackController.nextStartKeyTime && attackController.attackKeyCount <= attackController.nextEndKeyTime)
  487. {
  488. attackController.isAttackTriggerOn = true;
  489. attackController.attackTrigger.gameObject.SetActive(true);
  490. }
  491. else if (attackController.isAttackTriggerOn && attackController.attackKeyCount >= attackController.nextEndKeyTime)
  492. {
  493. attackController.isAttackTriggerOn = false;
  494. attackController.attackTrigger.gameObject.SetActive(false);
  495. attackController.SetNextKeyTimes();
  496. }
  497. if (attackController.attackTime <= 0)
  498. {
  499. if (isInSoulTower)
  500. {
  501. ChangeState(CharacterState.LockSoul);
  502. }
  503. else
  504. {
  505. ChangeState(CharacterState.Idle);
  506. }
  507. break;
  508. }
  509. rb.velocity = new Vector3(velocityAddition, rb.velocity.y, rb.velocity.z);
  510. break;
  511. case CharacterState.Die:
  512. if (dieKeepTime <= 0)
  513. {
  514. if (!isSpirit)
  515. {
  516. Corpse.allCorpsesNum += 1;
  517. Corpse.isChange = true;
  518. }
  519. gameObject.SetActive(false);
  520. break;
  521. }
  522. break;
  523. case CharacterState.Weak:
  524. if (rb.velocity.magnitude > 1)
  525. {
  526. if (!isBeBlownUp)
  527. {
  528. isBeBlownUp = true;
  529. ani.Play("hitted", 0, 0);
  530. }
  531. Vector3 vel = rb.velocity;
  532. if (foot.TrigGround && vel.y <= 0)
  533. {
  534. vel = Vector3.zero;
  535. }
  536. else
  537. {
  538. vel.x -= vel.x * decelerationRatio * Time.deltaTime;
  539. vel.y += extraFallGravity * Time.deltaTime;
  540. }
  541. //vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  542. //vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  543. rb.velocity = vel;
  544. }
  545. else
  546. {
  547. if (isBeBlownUp)
  548. {
  549. isBeBlownUp = false;
  550. }
  551. if (weakTime <= -0.1)
  552. {
  553. if (upFirstAfterWeaknessOrNot)
  554. {
  555. if (AdjustHeight())
  556. {
  557. ChangeState(CharacterState.Idle);
  558. }
  559. else
  560. {
  561. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "walk")
  562. {
  563. ani.Play("walk", 0, 0);
  564. }
  565. }
  566. }
  567. else
  568. {
  569. ChangeState(CharacterState.Idle);
  570. }
  571. break;
  572. }
  573. else
  574. {
  575. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
  576. {
  577. ani.Play("weak", 0, 0);
  578. rb.velocity = Vector3.zero;
  579. }
  580. }
  581. }
  582. break;
  583. case CharacterState.LockSoul:
  584. if (!isReturnSoulTower)
  585. {
  586. if (targetCharacter != null && targetCharacter.gameObject.layer == 8 && targetCharacter.isInSoulTower)
  587. {
  588. ChangeState(CharacterState.Idle);
  589. }
  590. else
  591. {
  592. isReturnSoulTower = true;
  593. }
  594. }
  595. else
  596. {
  597. if (transform.position.x - origSoulPos.x >= 0.2f)
  598. {
  599. rb.velocity = Vector3.right * (-moveSpeed + velocityAddition);
  600. if (bodyTrans.localScale.x < 0)
  601. {
  602. Turn();
  603. }
  604. }
  605. else if (origSoulPos.x - transform.position.x >= 0.2f)
  606. {
  607. rb.velocity = Vector3.right * (moveSpeed + velocityAddition);
  608. if (bodyTrans.localScale.x > 0)
  609. {
  610. Turn();
  611. }
  612. }
  613. else
  614. {
  615. ani.Play("idle", 0, 0);
  616. rb.velocity = Vector3.zero;
  617. transform.position = origSoulPos;
  618. isReturnSoulTower = false;
  619. targetCharacter = null;
  620. FaceToEneTower();
  621. }
  622. //锁魂塔内使魔返回原地过程中扫描到敌人时,停止返回并索敌攻击
  623. if (targetCharacter != null && targetCharacter.gameObject.layer == 8 && targetCharacter.isInSoulTower)
  624. {
  625. ChangeState(CharacterState.Idle);
  626. }
  627. }
  628. break;
  629. default:
  630. break;
  631. }
  632. }
  633. private void FaceToEneTower()
  634. {
  635. float dis = 1000000;
  636. GameObject to = null;
  637. foreach (GameObject g in TowerMap.enemyTowers)
  638. {
  639. float k = Vector3.Distance(g.transform.position, transform.position);
  640. if (k < dis)
  641. {
  642. dis = k;
  643. to = g;
  644. }
  645. }
  646. if (to != null && to.transform.position.x < transform.position.x)
  647. {
  648. if (bodyTrans.localScale.x < 0)
  649. {
  650. Turn();
  651. }
  652. }
  653. else
  654. {
  655. if (bodyTrans.localScale.x > 0)
  656. {
  657. Turn();
  658. }
  659. }
  660. }
  661. public override void ChangeState(CharacterState newState)
  662. {
  663. if (state == newState)
  664. {
  665. return;
  666. }
  667. switch (state)
  668. {
  669. case CharacterState.Idle:
  670. break;
  671. case CharacterState.Run:
  672. rb.velocity = Vector3.zero;
  673. break;
  674. case CharacterState.Rush:
  675. rb.velocity = Vector3.zero;
  676. break;
  677. case CharacterState.Rise:
  678. if (!canFly)
  679. {
  680. bodyCollider.SetActive(true);
  681. }
  682. break;
  683. case CharacterState.Fall:
  684. rb.velocity = Vector3.zero;
  685. break;
  686. //case CharacterState.Hurt:
  687. // break;
  688. case CharacterState.Coma:
  689. canMove = true;
  690. break;
  691. case CharacterState.Attack:
  692. break;
  693. case CharacterState.Die:
  694. isDie = false;
  695. break;
  696. case CharacterState.Weak:
  697. beRepelValue = totalBeRepelValue;
  698. newTotalWeakTime = totalWeakTime;
  699. if (canFly)
  700. {
  701. rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
  702. rb.useGravity = false;
  703. }
  704. break;
  705. case CharacterState.Float:
  706. canMove = true;
  707. break;
  708. case CharacterState.LockSoul:
  709. //isReturnSoulTower = true;
  710. break;
  711. default:
  712. break;
  713. }
  714. CharacterState oldState = state;
  715. state = newState;
  716. switch (newState)
  717. {
  718. case CharacterState.Idle:
  719. ani.Play("idle", 0, 0);
  720. rb.velocity = Vector3.zero;
  721. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  722. break;
  723. case CharacterState.Run:
  724. ani.Play("walk", 0, 0);
  725. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  726. break;
  727. case CharacterState.Rush:
  728. ani.Play("rush", 0, 0);
  729. break;
  730. case CharacterState.Fall:
  731. ani.Play("fall", 0, 0);
  732. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  733. break;
  734. //case CharacterState.Hurt:
  735. // ani.Play("hitted", 0, 0);
  736. // aniCollider.Play("Hurt", 0, 0);
  737. // invincibleTime = totalInvincibleTime;
  738. // hurtKeepTime = minHurtKeepTime;
  739. // //ani.Play("Invincible", 2, 0);
  740. // break;
  741. case CharacterState.Coma:
  742. //ani.Play("Coma", 0, 0);
  743. ani.Play("idle", 0, 0);
  744. pastComaTime = 0;
  745. rb.velocity = Vector3.zero;
  746. break;
  747. case CharacterState.Attack:
  748. break;
  749. case CharacterState.Die:
  750. ani.Play("die", 0, 0);
  751. isDie = true;
  752. dieKeepTime = totalDieKeepTime;
  753. break;
  754. case CharacterState.Weak:
  755. weakTime = newTotalWeakTime;
  756. rb.AddForce(weakForce);
  757. if (canFly)
  758. {
  759. rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
  760. rb.useGravity = true;
  761. flyHeight = Random.Range(minHeight, maxHeight);
  762. }
  763. break;
  764. case CharacterState.Float:
  765. canMove = false;
  766. break;
  767. case CharacterState.LockSoul:
  768. rb.velocity = Vector3.zero;
  769. ani.Play("walk", 0, 0);
  770. //FaceToEneTower();
  771. break;
  772. default:
  773. break;
  774. }
  775. }
  776. public void Attack_summon()
  777. {
  778. attackController.Attack_summon();
  779. Vector3 moveDir;
  780. if (PlayersInput.instance[playerID].bodyTrans.localScale.x > 0)
  781. {
  782. moveDir = Vector3.left;
  783. }
  784. else
  785. {
  786. moveDir = Vector3.right;
  787. }
  788. if (moveDir.x > 0.3f)
  789. {
  790. if (bodyTrans.localScale.x > 0)
  791. {
  792. Turn();
  793. }
  794. }
  795. else if (moveDir.x < -0.3f)
  796. {
  797. if (bodyTrans.localScale.x < 0)
  798. {
  799. Turn();
  800. }
  801. }
  802. invincibleTime = totalAttack_summonTime;
  803. attackTarget = targetCharacter;
  804. }
  805. public void Attack_march()
  806. {
  807. attackController.Attack_march();
  808. attackTarget = targetCharacter;
  809. }
  810. public void DropSouls()
  811. {
  812. int dropSoulNum = Random.Range(dropSoulMin, dropSoulMax + 1);
  813. if (dropSoulNum > 1)
  814. {
  815. for (int i = 0; i < dropSoulNum; i++)
  816. {
  817. float angleInterval = dropSoulAngle / (float)(dropSoulNum - 1);
  818. float angle = 90 + ((float)i - (float)(dropSoulNum - 1) / 2) * angleInterval;
  819. angle = angle / 180 * Mathf.PI;
  820. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  821. Vector3 dir = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);
  822. Soul soul = soulObj.GetComponent<Soul>();
  823. soul.Burst(dir * soulStartSpeed);
  824. }
  825. }
  826. else
  827. {
  828. GameObject soulObj = PoolManager.Instantiate(soulPrefab, transform.position);
  829. Vector3 dir = Vector3.up;
  830. Soul soul = soulObj.GetComponent<Soul>();
  831. soul.Burst(dir * soulStartSpeed);
  832. }
  833. }
  834. }