123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Mono;
- using Unity.VisualScripting;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public static Player Instance;
- public float MoveSpeed = 1;
- public void OnEnable()
- {
- Instance = this;
- }
- public void MoveL()
- {
- if (IsOver)
- {
- return;
- }
- if (transform.position.x > -2)
- {
- transform.position += Vector3.left * (Time.deltaTime * 5);
- }
- }
- public void MoveR()
- {
- if (IsOver)
- {
- return;
- }
- if (transform.position.x < 2)
- {
- transform.position += Vector3.right * (Time.deltaTime * 5);
- }
- }
- public void SetMoveSpeed(float value)
- {
- MoveSpeed += value;
- if (MoveSpeed < 0)
- {
- MoveSpeed = 0;
- }
- }
- public void StartGame()
- {
- _isEnable = true;
- IsOver = false;
- }
- private float _timer;
- private bool _isEnable;
- public bool IsOver;
- public void Update()
- {
- if (_isEnable)
- {
- _timer += Time.deltaTime;
- if (_timer >= 0.3f)
- {
- SetMoveSpeed(0.2f);
- // _isEnable = false;
- _timer = 0;
- }
- transform.position += Vector3.forward * (MoveSpeed * Time.deltaTime);
- if (MoveSpeed >= 10)
- {
- _isEnable = false;
- IsOver = true;
- InputPanel inputPanel = UIManager.Instance.GetPanel<InputPanel>();
- inputPanel.GameOver();
- }
- }
- }
- }
|