PlayerController.cs 22 KB

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