Repaired hole minigame

This commit is contained in:
2026-04-26 12:55:21 +02:00
parent 74fa735322
commit abbe4842fe
26 changed files with 4471 additions and 282 deletions

View File

@@ -7,10 +7,11 @@ using System.Collections.Generic;
public class ObjectSpawner : MonoBehaviour
{
public static ObjectSpawner Instance;
[SerializeField]
private List<GameObject> spawnedHoles = new List<GameObject>();
[Header("Prefaby")]
public GameObject[] objectPrefabs;
public GameObject holePrefab;
[Header("Počty")]
[Tooltip("Kolik předmětů spawnovat")]
@@ -28,12 +29,9 @@ public class ObjectSpawner : MonoBehaviour
public float minY = -5f;
public float maxY = 4f;
[Header("Rodiče pro přehlednost (volitelné)")]
public Transform objectParent;
public Transform holeParent;
private List<GameObject> spawnedObjects = new List<GameObject>();
private List<GameObject> spawnedHoles = new List<GameObject>();
void Awake()
{
@@ -57,41 +55,42 @@ public class ObjectSpawner : MonoBehaviour
LevelManager.Instance.ResetCounter();
}
SpawnHoles();
//SpawnHoles();
SpawnObjects();
}
void SpawnHoles()
{
for (int i = 0; i < holeCount; i++)
{
Vector2 pos = RandomPos(1f);
GameObject hole = Instantiate(holePrefab, pos, Quaternion.identity, holeParent);
Hole h = hole.GetComponent<Hole>();
if (h != null && holesMove)
{
h.hasMovement = true;
h.moveSpeed = holeMoveSpeed;
h.moveRange = new Vector2(Random.Range(0.8f, 1.8f), 0f);
}
spawnedHoles.Add(hole);
}
}
void SpawnObjects()
//void SpawnHoles()
//{
// for (int i = 0; i < holeCount; i++)
// {
// Vector2 pos = RandomPos(1f);
// GameObject hole = Instantiate(holePrefab, pos, Quaternion.identity, holeParent);
// Hole h = hole.GetComponent<Hole>();
// if (h != null && holesMove)
// {
// h.hasMovement = true;
// h.moveSpeed = holeMoveSpeed;
// h.moveRange = new Vector2(Random.Range(0.8f, 1.8f), 0f);
// }
// spawnedHoles.Add(hole);
// }
//}
public void SpawnObjects()
{
Debug.Log($"Spawning {objectCount} objects...");
for (int i = 0; i < objectCount; i++)
{
GameObject prefab = objectPrefabs[Random.Range(0, objectPrefabs.Length)];
Vector2 pos = RandomPos(0.5f);
GameObject obj = Instantiate(prefab, pos, Quaternion.identity, objectParent);
Vector3 pos = RandomPos(0.5f);
GameObject obj = Instantiate(prefab, pos, Quaternion.identity);
// Náhodná barva
SpriteRenderer sr = obj.GetComponent<SpriteRenderer>();
Renderer sr = obj.GetComponent<Renderer>();
if (sr != null)
sr.color = Random.ColorHSV(0f, 1f, 0.7f, 1f, 0.9f, 1f);
sr.sharedMaterial.color = Random.ColorHSV(0f, 1f, 0.7f, 1f, 0.9f, 1f);
spawnedObjects.Add(obj);
}
@@ -100,14 +99,17 @@ public class ObjectSpawner : MonoBehaviour
public void Clear()
{
foreach (var o in spawnedObjects) if (o != null) Destroy(o);
foreach (var h in spawnedHoles) if (h != null) Destroy(h);
spawnedObjects.Clear();
//foreach (var h in spawnedHoles) if (h != null) Destroy(h);
//spawnedObjects.Clear();
spawnedHoles.Clear();
}
Vector2 RandomPos(float margin) =>
new Vector2(
Vector3 RandomPos(float margin)
{
return new Vector3(
Random.Range(minX + margin, maxX - margin),
Random.Range(minY + margin, maxY - margin)
Random.Range(minY + margin, maxY - margin),
0.5f
);
}
}