Player.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Mono;
  5. using Unity.VisualScripting;
  6. using UnityEngine;
  7. public class Player : MonoBehaviour
  8. {
  9. public static Player Instance;
  10. public float MoveSpeed = 1;
  11. public void OnEnable()
  12. {
  13. Instance = this;
  14. }
  15. public void MoveL()
  16. {
  17. if (IsOver)
  18. {
  19. return;
  20. }
  21. if (transform.position.x > -2)
  22. {
  23. transform.position += Vector3.left * (Time.deltaTime * 5);
  24. }
  25. }
  26. public void MoveR()
  27. {
  28. if (IsOver)
  29. {
  30. return;
  31. }
  32. if (transform.position.x < 2)
  33. {
  34. transform.position += Vector3.right * (Time.deltaTime * 5);
  35. }
  36. }
  37. public void SetMoveSpeed(float value)
  38. {
  39. MoveSpeed += value;
  40. if (MoveSpeed < 0)
  41. {
  42. MoveSpeed = 0;
  43. }
  44. }
  45. public void StartGame()
  46. {
  47. _isEnable = true;
  48. IsOver = false;
  49. }
  50. private float _timer;
  51. private bool _isEnable;
  52. public bool IsOver;
  53. public void Update()
  54. {
  55. if (_isEnable)
  56. {
  57. _timer += Time.deltaTime;
  58. if (_timer >= 0.3f)
  59. {
  60. SetMoveSpeed(0.2f);
  61. // _isEnable = false;
  62. _timer = 0;
  63. }
  64. transform.position += Vector3.forward * (MoveSpeed * Time.deltaTime);
  65. if (MoveSpeed >= 10)
  66. {
  67. _isEnable = false;
  68. IsOver = true;
  69. InputPanel inputPanel = UIManager.Instance.GetPanel<InputPanel>();
  70. inputPanel.GameOver();
  71. }
  72. }
  73. }
  74. }