PlayerController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Spine;
  5. using Spine.Unity;
  6. using UnityEngine.LowLevel;
  7. using UnityEngine.Playables;
  8. using System.ComponentModel;
  9. using Unity.VisualScripting;
  10. public enum PlayerState
  11. {
  12. Idle = 1,
  13. Run = 2,
  14. Rise = 3,//空中上升
  15. Fall = 4,//空中下落
  16. Hurt = 5,
  17. Attack = 6,
  18. Summon = 7,
  19. Rush = 8,
  20. Die = 9,
  21. }
  22. public class PlayerController : MonoBehaviour
  23. {
  24. public SkeletonMecanim mecanim;
  25. public Skeleton skeleton;
  26. public Animator ani;
  27. public Rigidbody rb;
  28. public Foot foot;
  29. public Collider bodyCollider;
  30. public Collider jumpBodyCollider;
  31. public List<GameObject> demonicPrefabs;
  32. public List<Vector3> demonicSummonPos;
  33. public float extraRiseGravity = 0; //上升时额外重力加速度
  34. public float extraFallGravity = -10; //下落时额外重力加速度
  35. public float jumpSpeed = 10;
  36. //public float airJumpSpeed = 10;
  37. public float maxMoveSpeed = 5;
  38. //public float moveAcc = 5f;
  39. //public float airMoveAcc = 3f;
  40. public float rushSpeed = 100;
  41. public PlayerState state = PlayerState.Idle;
  42. [HideInInspector]
  43. public float invincibleTime;
  44. public float totalInvincibleTime = 2f;
  45. [HideInInspector]
  46. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  47. public float leaveGroundCanJumpTime = 0.1f;
  48. [HideInInspector]
  49. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  50. public float totalCacheJumpTime = 0.1f;
  51. [HideInInspector]
  52. public float hurtKeepTime;
  53. public float totalHurtKeepTime = 0.5f;
  54. [HideInInspector]
  55. public float attackTime;
  56. public float totalAttackTime = 0.5f;
  57. [HideInInspector]
  58. public float summonTime;
  59. public float totalSummonTime = 0.5f;
  60. [HideInInspector]
  61. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  62. public float totalCacheAttackTime = 0.1f;
  63. [HideInInspector]
  64. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  65. public float totalCacheSummonTime = 0.1f;
  66. [HideInInspector]
  67. public int cacheSummonId;
  68. [HideInInspector]
  69. public float rushTime;
  70. public float totalRushTime = 0.5f;
  71. [HideInInspector]
  72. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  73. public float totalCacheRushTime = 0.1f;
  74. public bool isDie = false;
  75. public bool btnJumpPress
  76. {
  77. get
  78. {
  79. return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  80. }
  81. }
  82. public bool isClickBtnJump;
  83. public bool btnRushPress
  84. {
  85. get
  86. {
  87. return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  88. }
  89. }
  90. public bool isClickBtnRush;
  91. public bool btnSouthPress
  92. {
  93. get
  94. {
  95. return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  96. }
  97. }
  98. public bool isClickBtnSouth;
  99. public bool btnEastPress
  100. {
  101. get
  102. {
  103. return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
  104. }
  105. }
  106. public bool isClickBtnEast;
  107. public bool btnWestPress
  108. {
  109. get
  110. {
  111. return Input.GetKeyDown(KeyCode.J) || isClickBtnWest;
  112. }
  113. }
  114. public bool isClickBtnWest;
  115. public bool btnNorthPress
  116. {
  117. get
  118. {
  119. return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  120. }
  121. }
  122. public bool isClickBtnNorth;
  123. public Vector2 leftDir
  124. {
  125. get
  126. {
  127. return new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
  128. }
  129. }
  130. private void Awake()
  131. {
  132. mecanim = GetComponent<SkeletonMecanim>();
  133. skeleton = mecanim.skeleton;
  134. ani = GetComponent<Animator>();
  135. ChangeState(PlayerState.Idle);
  136. }
  137. private void Update()
  138. {
  139. if (Input.GetKeyDown(KeyCode.LeftShift))
  140. {
  141. isClickBtnRush = true;
  142. }
  143. if (Input.GetKeyDown(KeyCode.Space))
  144. {
  145. isClickBtnJump = true;
  146. }
  147. if (Input.GetKeyDown(KeyCode.J))
  148. {
  149. isClickBtnWest = true;
  150. }
  151. if (Input.GetKeyDown(KeyCode.K))
  152. {
  153. isClickBtnSouth = true;
  154. }
  155. if (Input.GetKeyDown(KeyCode.L))
  156. {
  157. isClickBtnEast = true;
  158. }
  159. if (Input.GetKeyDown(KeyCode.I))
  160. {
  161. isClickBtnNorth = true;
  162. }
  163. }
  164. private void FixedUpdate()
  165. {
  166. OnState();
  167. }
  168. public void Jump()
  169. {
  170. SetUpSpeed(jumpSpeed);
  171. ani.Play("jump", 0, 0);
  172. }
  173. public void SetUpSpeed(float speed)
  174. {
  175. ChangeState(PlayerState.Rise);
  176. Vector3 velocity = rb.velocity;
  177. if (leftDir.x > 0.3f)
  178. {
  179. if (transform.localScale.x > 0)
  180. {
  181. Turn();
  182. }
  183. }
  184. else if (leftDir.x < -0.3f)
  185. {
  186. if (transform.localScale.x < 0)
  187. {
  188. Turn();
  189. }
  190. }
  191. velocity.y = speed;
  192. rb.velocity = velocity;
  193. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  194. }
  195. public void Turn()
  196. {
  197. transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
  198. }
  199. public void OnState()
  200. {
  201. cacheJumpTime -= Time.deltaTime;
  202. cacheAttackTime -= Time.deltaTime;
  203. cacheSummonTime -= Time.deltaTime;
  204. canJumpTime -= Time.deltaTime;
  205. invincibleTime -= Time.deltaTime;
  206. hurtKeepTime -= Time.deltaTime;
  207. attackTime -= Time.deltaTime;
  208. summonTime -= Time.deltaTime;
  209. rushTime -= Time.deltaTime;
  210. cacheRushTime -= Time.deltaTime;
  211. switch (state)
  212. {
  213. case PlayerState.Idle:
  214. if (btnWestPress || cacheAttackTime > 0)
  215. {
  216. ChangeState(PlayerState.Attack);
  217. break;
  218. }
  219. if (btnNorthPress)
  220. {
  221. Summon(0);
  222. break;
  223. }
  224. if (btnSouthPress)
  225. {
  226. Summon(1);
  227. break;
  228. }
  229. if (btnEastPress)
  230. {
  231. Summon(2);
  232. break;
  233. }
  234. if (cacheSummonTime > 0)
  235. {
  236. Summon(cacheSummonId);
  237. break;
  238. }
  239. if (btnRushPress || cacheRushTime > 0)
  240. {
  241. ChangeState(PlayerState.Rush);
  242. break;
  243. }
  244. if (btnJumpPress || cacheJumpTime > 0)
  245. {
  246. Jump();
  247. ChangeState(PlayerState.Rise);
  248. break;
  249. }
  250. if (!foot.TrigGround)
  251. {
  252. if (rb.velocity.y > 0)
  253. {
  254. ChangeState(PlayerState.Rise);
  255. break;
  256. }
  257. else
  258. {
  259. ChangeState(PlayerState.Fall);
  260. break;
  261. }
  262. }
  263. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  264. {
  265. ChangeState(PlayerState.Run);
  266. break;
  267. }
  268. canJumpTime = leaveGroundCanJumpTime;
  269. //rb.velocity = Vector3.zero;
  270. break;
  271. case PlayerState.Run:
  272. if (btnWestPress || cacheAttackTime > 0)
  273. {
  274. ChangeState(PlayerState.Attack);
  275. break;
  276. }
  277. if (btnNorthPress)
  278. {
  279. Summon(0);
  280. break;
  281. }
  282. if (btnSouthPress)
  283. {
  284. Summon(1);
  285. break;
  286. }
  287. if (btnEastPress)
  288. {
  289. Summon(2);
  290. break;
  291. }
  292. if (cacheSummonTime > 0)
  293. {
  294. Summon(cacheSummonId);
  295. break;
  296. }
  297. if (btnRushPress || cacheRushTime > 0)
  298. {
  299. ChangeState(PlayerState.Rush);
  300. break;
  301. }
  302. if (btnJumpPress || cacheJumpTime > 0)
  303. {
  304. Jump();
  305. break;
  306. }
  307. if (!foot.TrigGround)
  308. {
  309. if (rb.velocity.y > 0)
  310. {
  311. ChangeState(PlayerState.Rise);
  312. break;
  313. }
  314. else
  315. {
  316. ChangeState(PlayerState.Fall);
  317. break;
  318. }
  319. }
  320. if (leftDir.x < 0.3f && leftDir.x > -0.3f)
  321. {
  322. ChangeState(PlayerState.Idle);
  323. break;
  324. }
  325. canJumpTime = leaveGroundCanJumpTime;
  326. if (leftDir.x > 0.3f)
  327. {
  328. //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
  329. rb.velocity = Vector3.right * maxMoveSpeed;
  330. //if (rb.velocity.x > maxMoveSpeed)
  331. //{
  332. // rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  333. //}
  334. if (transform.localScale.x > 0)
  335. {
  336. Turn();
  337. }
  338. }
  339. else if (leftDir.x < -0.3f)
  340. {
  341. //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
  342. rb.velocity = Vector3.left * maxMoveSpeed;
  343. //if (rb.velocity.x < -maxMoveSpeed)
  344. //{
  345. // rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  346. //}
  347. if (transform.localScale.x < 0)
  348. {
  349. Turn();
  350. }
  351. }
  352. break;
  353. case PlayerState.Rise:
  354. if (btnRushPress || cacheRushTime > 0)
  355. {
  356. ChangeState(PlayerState.Rush);
  357. break;
  358. }
  359. if (rb.velocity.y <= 0)
  360. {
  361. ChangeState(PlayerState.Fall);
  362. break;
  363. }
  364. //if (btnJumpPress || cacheJumpTime > 0)
  365. //{
  366. // if (!airJumped && rb.velocity.y < airJumpSpeed)
  367. // {
  368. // airJumped = true;
  369. // AirJump();
  370. // break;
  371. // }
  372. //}
  373. if (btnRushPress)
  374. {
  375. cacheRushTime = totalCacheRushTime;
  376. }
  377. if (btnJumpPress)
  378. {
  379. cacheJumpTime = totalCacheJumpTime;
  380. }
  381. if (btnWestPress)
  382. {
  383. cacheAttackTime = totalCacheAttackTime;
  384. }
  385. if (btnNorthPress)
  386. {
  387. cacheSummonTime = totalCacheSummonTime;
  388. cacheSummonId = 0;
  389. }
  390. if (btnSouthPress)
  391. {
  392. cacheSummonTime = totalCacheSummonTime;
  393. cacheSummonId = 1;
  394. }
  395. if (btnEastPress)
  396. {
  397. cacheSummonTime = totalCacheSummonTime;
  398. cacheSummonId = 2;
  399. }
  400. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  401. AirMove();
  402. break;
  403. case PlayerState.Fall:
  404. if (btnRushPress || cacheRushTime > 0)
  405. {
  406. ChangeState(PlayerState.Rush);
  407. break;
  408. }
  409. if (foot.TrigGround)
  410. {
  411. ChangeState(PlayerState.Idle);
  412. break;
  413. }
  414. //if (foot.canStepPlayers.Count > 0)
  415. //{
  416. // Jump(jumpSpeed / 2);
  417. // StepOther();
  418. // break;
  419. //}
  420. //if (foot.canStepEnemyList.Count > 0)
  421. //{
  422. // Jump(jumpSpeed / 2);
  423. // StepEnemy();
  424. // break;
  425. //}
  426. //if (btnJumpPress || cacheJumpTime > 0)
  427. //{
  428. // if (!airJumped)
  429. // {
  430. // airJumped = true;
  431. // AirJump();
  432. // break;
  433. // }
  434. // else if (canJumpTick >= runner.Tick)
  435. // {
  436. // Jump();
  437. // break;
  438. // }
  439. //}
  440. if (btnRushPress)
  441. {
  442. cacheRushTime = totalCacheRushTime;
  443. }
  444. if (btnJumpPress)
  445. {
  446. cacheJumpTime = totalCacheJumpTime;
  447. }
  448. if (btnWestPress)
  449. {
  450. cacheAttackTime = totalCacheAttackTime;
  451. }
  452. if (btnNorthPress)
  453. {
  454. cacheSummonTime = totalCacheSummonTime;
  455. cacheSummonId = 0;
  456. }
  457. if (btnSouthPress)
  458. {
  459. cacheSummonTime = totalCacheSummonTime;
  460. cacheSummonId = 1;
  461. }
  462. if (btnEastPress)
  463. {
  464. cacheSummonTime = totalCacheSummonTime;
  465. cacheSummonId = 2;
  466. }
  467. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  468. AirMove();
  469. break;
  470. case PlayerState.Hurt:
  471. if (hurtKeepTime <= 0)
  472. {
  473. ChangeState(PlayerState.Idle);
  474. break;
  475. }
  476. if (btnRushPress)
  477. {
  478. cacheRushTime = totalCacheRushTime;
  479. }
  480. if (btnJumpPress)
  481. {
  482. cacheJumpTime = totalCacheJumpTime;
  483. }
  484. if (btnWestPress)
  485. {
  486. cacheAttackTime = totalCacheAttackTime;
  487. }
  488. if (btnNorthPress)
  489. {
  490. cacheSummonTime = totalCacheSummonTime;
  491. cacheSummonId = 0;
  492. }
  493. if (btnSouthPress)
  494. {
  495. cacheSummonTime = totalCacheSummonTime;
  496. cacheSummonId = 1;
  497. }
  498. if (btnEastPress)
  499. {
  500. cacheSummonTime = totalCacheSummonTime;
  501. cacheSummonId = 2;
  502. }
  503. if (!foot.TrigGround)
  504. {
  505. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  506. }
  507. rb.velocity = rb.velocity / 5 * 4;
  508. break;
  509. case PlayerState.Attack:
  510. if (attackTime <= 0)
  511. {
  512. ChangeState(PlayerState.Idle);
  513. break;
  514. }
  515. if (btnRushPress)
  516. {
  517. cacheRushTime = totalCacheRushTime;
  518. }
  519. if (btnJumpPress)
  520. {
  521. cacheJumpTime = totalCacheJumpTime;
  522. }
  523. if (btnWestPress)
  524. {
  525. cacheAttackTime = totalCacheAttackTime;
  526. }
  527. if (btnNorthPress)
  528. {
  529. cacheSummonTime = totalCacheSummonTime;
  530. cacheSummonId = 0;
  531. }
  532. if (btnSouthPress)
  533. {
  534. cacheSummonTime = totalCacheSummonTime;
  535. cacheSummonId = 1;
  536. }
  537. if (btnEastPress)
  538. {
  539. cacheSummonTime = totalCacheSummonTime;
  540. cacheSummonId = 2;
  541. }
  542. break;
  543. case PlayerState.Summon:
  544. if (summonTime <= 0)
  545. {
  546. ChangeState(PlayerState.Idle);
  547. break;
  548. }
  549. if (btnRushPress)
  550. {
  551. cacheRushTime = totalCacheRushTime;
  552. }
  553. if (btnJumpPress)
  554. {
  555. cacheJumpTime = totalCacheJumpTime;
  556. }
  557. if (btnWestPress)
  558. {
  559. cacheAttackTime = totalCacheAttackTime;
  560. }
  561. if (btnNorthPress)
  562. {
  563. cacheSummonTime = totalCacheSummonTime;
  564. cacheSummonId = 0;
  565. }
  566. if (btnSouthPress)
  567. {
  568. cacheSummonTime = totalCacheSummonTime;
  569. cacheSummonId = 1;
  570. }
  571. if (btnEastPress)
  572. {
  573. cacheSummonTime = totalCacheSummonTime;
  574. cacheSummonId = 2;
  575. }
  576. break;
  577. case PlayerState.Rush:
  578. if (rushTime <= 0)
  579. {
  580. ChangeState(PlayerState.Idle);
  581. break;
  582. }
  583. if (transform.localScale.x > 0)
  584. {
  585. rb.velocity = Vector3.left * rushSpeed;
  586. }
  587. else
  588. {
  589. rb.velocity = Vector3.right * rushSpeed;
  590. }
  591. break;
  592. default:
  593. break;
  594. }
  595. isClickBtnRush = false;
  596. isClickBtnJump = false;
  597. isClickBtnSouth = false;
  598. isClickBtnEast = false;
  599. isClickBtnNorth = false;
  600. isClickBtnWest = false;
  601. }
  602. public void ChangeState(PlayerState newState)
  603. {
  604. switch (state)
  605. {
  606. case PlayerState.Idle:
  607. break;
  608. case PlayerState.Run:
  609. break;
  610. case PlayerState.Rise:
  611. break;
  612. case PlayerState.Fall:
  613. break;
  614. case PlayerState.Hurt:
  615. break;
  616. case PlayerState.Attack:
  617. break;
  618. case PlayerState.Summon:
  619. break;
  620. case PlayerState.Rush:
  621. break;
  622. case PlayerState.Die:
  623. isDie = false;
  624. break;
  625. default:
  626. break;
  627. }
  628. PlayerState oldState = state;
  629. state = newState;
  630. switch (newState)
  631. {
  632. case PlayerState.Idle:
  633. bodyCollider.enabled = true;
  634. jumpBodyCollider.enabled = false;
  635. if (oldState == PlayerState.Fall)
  636. {
  637. ani.Play("fall_end", 0, 0);
  638. }
  639. else
  640. {
  641. ani.Play("idle", 0, 0);
  642. }
  643. rb.velocity = Vector3.zero;
  644. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  645. break;
  646. case PlayerState.Run:
  647. bodyCollider.enabled = true;
  648. jumpBodyCollider.enabled = false;
  649. ani.Play("run", 0, 0);
  650. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  651. break;
  652. case PlayerState.Rise:
  653. bodyCollider.enabled = false;
  654. jumpBodyCollider.enabled = true;
  655. canJumpTime = 0;
  656. break;
  657. case PlayerState.Fall:
  658. bodyCollider.enabled = false;
  659. jumpBodyCollider.enabled = true;
  660. ani.Play("fall", 0, 0);
  661. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  662. break;
  663. case PlayerState.Hurt:
  664. bodyCollider.enabled = false;
  665. jumpBodyCollider.enabled = true;
  666. ani.Play("hitted", 0, 0);
  667. hurtKeepTime = totalHurtKeepTime;
  668. invincibleTime = totalInvincibleTime;
  669. //ani.Play("Invincible", 2, 0);
  670. break;
  671. case PlayerState.Attack:
  672. bodyCollider.enabled = true;
  673. jumpBodyCollider.enabled = false;
  674. ani.Play("attack1", 0, 0);
  675. attackTime = totalAttackTime;
  676. break;
  677. case PlayerState.Summon:
  678. bodyCollider.enabled = true;
  679. jumpBodyCollider.enabled = false;
  680. ani.Play("summon", 0, 0);
  681. summonTime = totalSummonTime;
  682. break;
  683. case PlayerState.Rush:
  684. bodyCollider.enabled = true;
  685. jumpBodyCollider.enabled = false;
  686. ani.Play("rush_loop", 0, 0);
  687. rushTime = totalRushTime;
  688. break;
  689. case PlayerState.Die:
  690. bodyCollider.enabled = false;
  691. jumpBodyCollider.enabled = false;
  692. ani.Play("die", 0, 0);
  693. isDie = true;
  694. break;
  695. default:
  696. break;
  697. }
  698. }
  699. public void AirMove()
  700. {
  701. if (leftDir.x > 0.3f)
  702. {
  703. //rb.velocity += Vector3.right * airMoveAcc * deltaTime;
  704. ////rb.velocity = Vector3.right * maxMoveSpeed;
  705. //if (rb.velocity.x > maxMoveSpeed)
  706. //{
  707. rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  708. //}
  709. if (transform.localScale.x > 0)
  710. {
  711. Turn();
  712. }
  713. }
  714. else if (leftDir.x < -0.3f)
  715. {
  716. //rb.velocity -= Vector3.right * airMoveAcc * deltaTime;
  717. ////rb.velocity = Vector3.left * maxMoveSpeed;
  718. //if (rb.velocity.x < -maxMoveSpeed)
  719. //{
  720. rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
  721. //}
  722. if (transform.localScale.x < 0)
  723. {
  724. Turn();
  725. }
  726. }
  727. else
  728. {
  729. rb.velocity = new Vector3(0, rb.velocity.y, rb.velocity.z);
  730. }
  731. }
  732. public void Summon(int id)
  733. {
  734. print("Summon:" + id);
  735. ChangeState(PlayerState.Summon);
  736. if (id >= demonicPrefabs.Count)
  737. {
  738. Debug.LogError("未配置" + id + "号使魔");
  739. return;
  740. }
  741. if (id >= demonicSummonPos.Count)
  742. {
  743. Debug.LogError("未配置" + id + "号使魔召唤位置");
  744. return;
  745. }
  746. GameObject prefab = demonicPrefabs[id];
  747. GameObject demonicObj = Instantiate(prefab);
  748. Demonic demonic = demonicObj.GetComponent<Demonic>();
  749. demonicObj.transform.parent = null;
  750. demonicObj.transform.localEulerAngles = Vector3.zero;
  751. Vector3 offset = demonicSummonPos[id];
  752. if (transform.localScale.x > 0)
  753. {
  754. demonicObj.transform.position = transform.position + offset;
  755. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  756. }
  757. else
  758. {
  759. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  760. demonicObj.transform.localScale = new Vector3(-1, 1, 1);
  761. }
  762. demonic.ChangeState(DemonicState.Attack1);
  763. }
  764. }