added coins

This commit is contained in:
MrTorex committed 2026-03-07 15:02:58 +03:00
1 parent 4a8a8ae916
commit 9e5f46b48c
37 files changed
+7536 -79

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c57a434a19fd4a2b946dc4a88df4929d
timeCreated: 1772884699
+31
View File
@@ -0,0 +1,31 @@
using UnityEngine;
using PrimeTween;
namespace Code.Gameplay.Coin
{
public class Coin : MonoBehaviour
{
public Vector3 rotationAngle = new(0, 360, 0);
public float rotationDuration = 10f;
public float amplitude = 0.5f;
public float cycleDuration = 2f;
private void Start()
{
Tween.LocalEulerAngles(transform,
startValue: Vector3.zero,
endValue: rotationAngle,
duration: rotationDuration,
cycles: -1,
ease: Ease.Linear);
Tween.LocalPositionY(transform,
endValue: transform.localPosition.y + amplitude,
duration: cycleDuration / 2,
cycles: -1,
cycleMode: CycleMode.Yoyo,
ease: Ease.InOutSine);
}
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 83c61140120e4627941c775e56bbfd98
timeCreated: 1772884705
+27 -6
View File
@@ -20,12 +20,15 @@ namespace Code.Gameplay.Level
[Header("Obstacles Settings")] [SerializeField]
private GameObject[] lowObstacles;
[SerializeField] private GameObject[] highObstacles;
[SerializeField] private GameObject[] movingLowObstacles;
[SerializeField] private GameObject[] movingHighObstacles;
[Range(0, 100)] [SerializeField] private int obstacleChance = 40;
[SerializeField] private float laneDistance = 5f;
[Header("Coins Settings")]
[SerializeField] private GameObject coinPrefab;
[Range(0, 100)] [SerializeField] private int coinChance = 50;
private readonly List<GameObject> _activeTiles = new();
private readonly List<GameObject> _activeEnvironment = new();
@@ -57,15 +60,16 @@ namespace Code.Gameplay.Level
if (spawnItems)
{
SpawnObstacle(_spawnZ);
var occupiedLane = SpawnObstacle(_spawnZ);
SpawnCoins(_spawnZ, occupiedLane);
}
_spawnZ += tileLength;
}
private void SpawnObstacle(float zPos)
private int SpawnObstacle(float zPos)
{
if (Random.Range(0, 100) > obstacleChance) return;
if (Random.Range(0, 100) > obstacleChance) return -2;
var lane = Random.Range(-1, 2);
var spawnPos = new Vector3(lane * laneDistance, 0, zPos);
@@ -86,9 +90,26 @@ namespace Code.Gameplay.Level
var obs = Instantiate(prefab, spawnPos, Quaternion.Euler(0, 180, 0));
obs.transform.SetParent(_activeTiles[^1].transform);
}
return lane;
}
private void SpawnCoins(float zPos, int occupiedLane)
{
if (Random.Range(0, 100) > coinChance) return;
var coinLane = Random.Range(-1, 2);
if (coinLane == occupiedLane) coinLane = (coinLane + 1 > 1) ? -1 : coinLane + 1;
for (var i = 0; i < 2; i++)
{
var spawnPos = new Vector3(coinLane * laneDistance, 1f, zPos + (i * 2f));
var coin = Instantiate(coinPrefab, spawnPos, Quaternion.identity);
coin.transform.SetParent(_activeTiles[^1].transform);
}
}
private GameObject GetRandom(GameObject[] array)
private static GameObject GetRandom(GameObject[] array)
{
return array.Length > 0 ? array[Random.Range(0, array.Length)] : null;
}
@@ -72,5 +72,15 @@ namespace Code.Gameplay.Player
{
forwardSpeed += amount;
}
private void OnTriggerEnter(Collider foreign)
{
if (foreign.CompareTag("Coin"))
{
UI.GameplayController.Instance.AddCoin();
Destroy(foreign.gameObject);
}
}
}
}