Spirits_Dash.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Spirits_Dash : MonoBehaviour
  5. {
  6. public float moveSpeed;
  7. public Rigidbody rb;
  8. public Demonic demonic;
  9. public bool isDash;
  10. [HideInInspector]
  11. public float time;
  12. public float dashTime = 0.8f;
  13. public GameObject dashAttackEffect;
  14. public float offset;
  15. public DashEffect dashEffect;
  16. private void Update()
  17. {
  18. if (isDash)
  19. {
  20. time += Time.deltaTime;
  21. Dash();
  22. if(time >= dashTime)
  23. {
  24. DashAttackEffect();
  25. dashEffect.canHit = false;
  26. demonic.ChangeState(CharacterState.Fall);
  27. this.enabled = false;
  28. }
  29. if(time >= 1.33f)
  30. {
  31. }
  32. }
  33. }
  34. void DashAttackEffect()
  35. {
  36. rb.velocity = Vector3.zero;
  37. }
  38. private void Dash()
  39. {
  40. if (demonic.player.bodyTrans.localScale.x < 0)
  41. {
  42. if (demonic.bodyTrans.localScale.x > 0)
  43. {
  44. demonic.bodyTrans.localScale = new Vector3(-demonic.bodyTrans.localScale.x,
  45. demonic.bodyTrans.localScale.y, demonic.bodyTrans.localScale.z);
  46. }
  47. rb.velocity = Vector3.right * moveSpeed;
  48. dashEffect.offset = offset;
  49. }
  50. if (demonic.player.bodyTrans.localScale.x > 0)
  51. {
  52. if(demonic.bodyTrans.localScale.x < 0)
  53. {
  54. demonic.bodyTrans.localScale = new Vector3(-demonic.bodyTrans.localScale.x,
  55. demonic.bodyTrans.localScale.y, demonic.bodyTrans.localScale.z);
  56. }
  57. rb.velocity = Vector3.left * moveSpeed;
  58. dashEffect.offset = -offset;
  59. }
  60. }
  61. }