Player.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Player : MonoBehaviour
  6. {
  7. public static Player Instance;
  8. public float MoveSpeed = 1;
  9. public void OnEnable()
  10. {
  11. Instance = this;
  12. }
  13. public void MoveL()
  14. {
  15. if (transform.position.x > -2)
  16. {
  17. transform.position += Vector3.left*0.5f;
  18. }
  19. }
  20. public void MoveR()
  21. {
  22. if (transform.position.x < 2)
  23. {
  24. transform.position += Vector3.right*0.5f;
  25. }
  26. }
  27. public void SetMoveSpeed(float value)
  28. {
  29. MoveSpeed += value;
  30. }
  31. public void StartGame()
  32. {
  33. _isEnable = true;
  34. IsOver = false;
  35. }
  36. private float _timer;
  37. private bool _isEnable;
  38. public bool IsOver;
  39. public void Update()
  40. {
  41. if (_isEnable)
  42. {
  43. _timer += Time.deltaTime;
  44. if (_timer >= 0.3f)
  45. {
  46. SetMoveSpeed(0.5f);
  47. // _isEnable = false;
  48. _timer = 0;
  49. }
  50. transform.position += Vector3.forward * (MoveSpeed * Time.deltaTime);
  51. if (MoveSpeed >= 10)
  52. {
  53. _isEnable = false;
  54. IsOver = true;
  55. }
  56. }
  57. }
  58. }