added speed change and death

This commit is contained in:
MrTorex committed 2026-03-07 23:43:08 +03:00
1 parent 9e5f46b48c
commit 08e050ffd3
6 files changed
+1437 -5

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 725a8d40dde446e6843ad182b3474d9d
timeCreated: 1772914582
@@ -0,0 +1,33 @@
using UnityEngine;
using Code.Gameplay.Player;
namespace Code.Gameplay.Management
{
public class GameSpeedManager : MonoBehaviour
{
[SerializeField] private PlayerController playerController;
[SerializeField] private float speedMultiplier = 1.2f;
[SerializeField] private float timeInterval = 10f;
private float _timer;
private void Update()
{
_timer += Time.deltaTime;
if (_timer >= timeInterval)
{
AccelerateGame();
_timer = 0;
}
}
private void AccelerateGame()
{
if (playerController)
{
playerController.IncreaseSpeed(speedMultiplier);
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b5f84b26f43465ab2930bb64735922d
timeCreated: 1772914590
@@ -5,14 +5,18 @@ namespace Code.Gameplay.Player
public class PlayerController : MonoBehaviour
{
[SerializeField] private float forwardSpeed = 10f;
[SerializeField] private float maxSpeed = 40f;
[SerializeField] private float laneDistance = 5f;
[SerializeField] private float jumpForce = 8f;
[SerializeField] private float jumpForce = 11f;
[SerializeField] private float gravity = 20f;
private int _targetLane = 1;
private CharacterController _controller;
private Vector3 _direction;
public System.Action OnPlayerDeath;
private bool _isDead = false;
private void Start()
{
@@ -21,6 +25,8 @@ namespace Code.Gameplay.Player
private void Update()
{
if (_isDead) return;
if (UnityEngine.Input.GetKeyDown(KeyCode.RightArrow) || UnityEngine.Input.GetKeyDown(KeyCode.D))
{
_targetLane = Mathf.Min(_targetLane + 1, 2);
@@ -66,11 +72,16 @@ namespace Code.Gameplay.Player
var finalMove = new Vector3(moveX, _direction.y * Time.deltaTime, _direction.z * Time.deltaTime);
_controller.Move(finalMove);
CheckForDeath();
}
public void IncreaseSpeed(float amount)
{
forwardSpeed += amount;
if (forwardSpeed < maxSpeed)
{
var desirableSpeed = forwardSpeed + amount;
forwardSpeed = Mathf.Min(desirableSpeed, maxSpeed);
}
}
private void OnTriggerEnter(Collider foreign)
@@ -82,5 +93,23 @@ namespace Code.Gameplay.Player
Destroy(foreign.gameObject);
}
}
private void CheckForDeath()
{
if (_isDead) return;
if (Time.timeSinceLevelLoad > 1f && _controller.velocity.z <= 0.1f)
{
Die();
}
}
private void Die()
{
_isDead = true;
forwardSpeed = 0;
_direction = Vector3.zero;
OnPlayerDeath?.Invoke();
}
}
}