Project
This commit is contained in:
1 parent
e1a474d4ac
commit
24b1157026
164 files changed
+68527
No files matched your search
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78f8edda66b14b40b372b2aed7fc5d6b
|
||||
timeCreated: 1777835857
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class GameplayManager : MonoBehaviour
|
||||
{
|
||||
public static GameplayManager Instance { get; private set; }
|
||||
|
||||
private bool _onPause;
|
||||
public bool OnPause => _onPause;
|
||||
|
||||
[SerializeField] [Range(0f, 30f)] private float gameSpeed;
|
||||
|
||||
private float _currentGameSpeed;
|
||||
public float GameSpeed => _currentGameSpeed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
_currentGameSpeed = gameSpeed;
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
ResetGame();
|
||||
ResumeGame();
|
||||
}
|
||||
public void PlayerDead()
|
||||
{
|
||||
PauseGame();
|
||||
}
|
||||
|
||||
public void PauseGame()
|
||||
{
|
||||
_onPause = true;
|
||||
_currentGameSpeed = 0f;
|
||||
}
|
||||
public void ResumeGame()
|
||||
{
|
||||
_onPause = false;
|
||||
_currentGameSpeed = gameSpeed;
|
||||
}
|
||||
private void ResetGame()
|
||||
{
|
||||
PassingObjectsManager.Instance.ResetObjects();
|
||||
PlayerScoreService.Instance.ResetScore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cdf72ee53f84d76ab57d0dcd7798e75
|
||||
timeCreated: 1777833499
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Alchemy.Inspector;
|
||||
using Code.PassingObjects;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class PassingObjectsManager : MonoBehaviour
|
||||
{
|
||||
[TabGroup("Spawn")] [SerializeField] private List<Transform> spawnPoints;
|
||||
[TabGroup("Spawn")] [SerializeField] private List<GameObject> prefabs;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float behindPlayerThreshold;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private float obstacleCooldown;
|
||||
|
||||
[TabGroup("Gameplay")] [SerializeField]
|
||||
private List<PassingObjectsPreset> obstaclesPresets;
|
||||
|
||||
private List<GameObject> _spawnedObjects = new();
|
||||
public float BehindPlayerThreshold => behindPlayerThreshold;
|
||||
public static PassingObjectsManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void ResetObjects()
|
||||
{
|
||||
foreach (var spawnedObject in _spawnedObjects)
|
||||
{
|
||||
Destroy(spawnedObject);
|
||||
}
|
||||
_spawnedObjects.Clear();
|
||||
_timer = 0f;
|
||||
}
|
||||
public void KillChild(PassingObject child)
|
||||
{
|
||||
if (!_spawnedObjects.Contains(child.gameObject)) return;
|
||||
|
||||
_spawnedObjects.Remove(child.gameObject);
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
private float _timer;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(GameplayManager.Instance.OnPause) return;
|
||||
|
||||
_timer += Time.deltaTime;
|
||||
|
||||
if (!(_timer > obstacleCooldown)) return;
|
||||
|
||||
_timer = 0f;
|
||||
|
||||
if (prefabs.Count == 0 && obstaclesPresets.Count > 0) return;
|
||||
|
||||
var presetId = Random.Range(0, obstaclesPresets.Count);
|
||||
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId1],
|
||||
spawnPoints[0].position,
|
||||
spawnPoints[0].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId2],
|
||||
spawnPoints[1].position,
|
||||
spawnPoints[1].rotation));
|
||||
_spawnedObjects.Add(
|
||||
Instantiate(
|
||||
prefabs[obstaclesPresets[presetId].prefabId3],
|
||||
spawnPoints[2].position,
|
||||
spawnPoints[2].rotation));
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class PassingObjectsPreset
|
||||
{
|
||||
public int prefabId1;
|
||||
public int prefabId2;
|
||||
public int prefabId3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95f7cf3ef95244ca9903d804eb9463d7
|
||||
timeCreated: 1777828525
|
||||
@@ -0,0 +1,37 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.GameplayServices
|
||||
{
|
||||
public class PlayerScoreService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
|
||||
private int _score;
|
||||
|
||||
public static PlayerScoreService Instance { get; private set; }
|
||||
public int Score => _score;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void AddScore(int score)
|
||||
{
|
||||
_score += score;
|
||||
UpdateScoreTextWithScoreValue();
|
||||
}
|
||||
|
||||
private void UpdateScoreTextWithScoreValue()
|
||||
{
|
||||
scoreText.text = _score.ToString();
|
||||
}
|
||||
|
||||
public void ResetScore()
|
||||
{
|
||||
_score = 0;
|
||||
scoreText.text = _score.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e330c677aa54ef6a017e7bab9ebd104
|
||||
timeCreated: 1777831807
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4c224dc489f427790d21c8295395b9a
|
||||
timeCreated: 1777831140
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Code.GameplayServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.PassingObjects
|
||||
{
|
||||
public class Coin : PassingObject
|
||||
{
|
||||
[SerializeField] private int countOnActivate;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
PlayerScoreService.Instance.AddScore(countOnActivate);
|
||||
PassingObjectsManager.Instance.KillChild(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9268e6ab4ed243439fd47dc649c5d0ab
|
||||
timeCreated: 1777831148
|
||||
@@ -0,0 +1,16 @@
|
||||
using Code.GameplayServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.PassingObjects
|
||||
{
|
||||
public class PassingObject : MonoBehaviour
|
||||
{
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (transform.position.z < PassingObjectsManager.Instance.BehindPlayerThreshold)
|
||||
PassingObjectsManager.Instance.KillChild(this);
|
||||
|
||||
transform.position -= new Vector3(0, 0, GameplayManager.Instance.GameSpeed * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e01aa934ad27493aa737859fe6fe382d
|
||||
timeCreated: 1777827872
|
||||
@@ -0,0 +1,10 @@
|
||||
using Code.GameplayServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.PassingObjects
|
||||
{
|
||||
public class Wall : PassingObject
|
||||
{
|
||||
private void OnTriggerEnter(Collider other) => GameplayManager.Instance.PlayerDead();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 102f91b6848f4161b7f4fb9681c2bc79
|
||||
timeCreated: 1777833598
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b1b7dc54731415ba4ebb9e371aa2d83
|
||||
timeCreated: 1777836036
|
||||
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Code.Player
|
||||
{
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform[] runPositions = new Transform[3];
|
||||
[SerializeField] private float jumpStrength;
|
||||
private Rigidbody _rigidbody;
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
|
||||
InputSystem.actions.actionMaps[0].actions[0].performed += Jump;
|
||||
InputSystem.actions.actionMaps[0].actions[1].performed += MoveRight;
|
||||
InputSystem.actions.actionMaps[0].actions[2].performed += MoveLeft;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
InputSystem.actions.actionMaps[0].actions[0].performed -= Jump;
|
||||
InputSystem.actions.actionMaps[0].actions[1].performed -= MoveRight;
|
||||
InputSystem.actions.actionMaps[0].actions[2].performed -= MoveLeft;
|
||||
}
|
||||
|
||||
private void Jump(InputAction.CallbackContext context)
|
||||
{
|
||||
_rigidbody.AddForce(new(0,jumpStrength,0), ForceMode.Impulse);
|
||||
}
|
||||
|
||||
private int _currentTarget = 1;
|
||||
private void MoveRight(InputAction.CallbackContext context)
|
||||
{
|
||||
if(_currentTarget != 2) _currentTarget++;
|
||||
ChangePosition();
|
||||
}
|
||||
private void MoveLeft(InputAction.CallbackContext context)
|
||||
{
|
||||
if(_currentTarget != 0) _currentTarget--;
|
||||
ChangePosition();
|
||||
}
|
||||
|
||||
private void ChangePosition()
|
||||
{
|
||||
transform.position = runPositions[_currentTarget].position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd850809c4f498280fac867c038af4d
|
||||
timeCreated: 1777827949
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90a327d7b3d4444e9ebe6dc89bfdd0e2
|
||||
timeCreated: 1777835085
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Code.GameplayServices;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class RestartPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button restartButton;
|
||||
[SerializeField] private TMP_Text scoreText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
restartButton.onClick.AddListener(RestartGame);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
restartButton.onClick.RemoveListener(RestartGame);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ShowScore();
|
||||
}
|
||||
|
||||
private void ShowScore()
|
||||
{
|
||||
scoreText.text = PlayerScoreService.Instance.Score.ToString();
|
||||
}
|
||||
|
||||
private void RestartGame() => GameplayManager.Instance.RestartGame();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29c7d40f01be4cae9ff1aa28cf88cfe3
|
||||
timeCreated: 1777835101
|
||||
Reference in new issue
Block a user