scena_minigame-kabely. ps pridat ui

This commit is contained in:
2026-02-21 12:32:31 +01:00
parent 9f71b6a84a
commit 8f62dc8873
3 changed files with 1206 additions and 0 deletions

80
Assets/kabely.cs Normal file
View File

@@ -0,0 +1,80 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class CableMiniGame : MonoBehaviour
{
[System.Serializable]
public class Cable
{
public string colorName; // Název barvy kabelu
public Button sourceButton; // Zdrojový konektor
public Button targetButton; // Cílový konektor
public Image cableImage; // Pro změnu barvy kabelu
}
public Cable[] cables;
public string previousSceneName; // Scéna kam se vrátit při chybě
public Color wrongAttemptColor = Color.white; // Bliknutí při špatném pokusu
public float blinkDuration = 0.2f;
private string selectedColor = null;
void Start()
{
foreach (var cable in cables)
{
cable.sourceButton.onClick.AddListener(() => OnSourceClicked(cable));
cable.targetButton.onClick.AddListener(() => OnTargetClicked(cable));
}
}
void OnSourceClicked(Cable cable)
{
selectedColor = cable.colorName;
Debug.Log("Vybrána barva: " + selectedColor);
}
void OnTargetClicked(Cable cable)
{
if (selectedColor == null)
return;
if (selectedColor == cable.colorName)
{
// Správné propojení
Debug.Log("Správně!");
cable.cableImage.color = GetColorFromName(selectedColor);
}
else
{
// Špatné propojení reset scény
Debug.Log("Špatně, restart!");
StartCoroutine(BlinkAndReset(cable.cableImage));
}
selectedColor = null;
}
Color GetColorFromName(string name)
{
switch (name.ToLower())
{
case "red": return Color.red;
case "blue": return Color.blue;
case "green": return Color.green;
case "yellow": return Color.yellow;
case "purple": return new Color(0.5f, 0, 0.5f);
default: return Color.white;
}
}
System.Collections.IEnumerator BlinkAndReset(Image img)
{
Color original = img.color;
img.color = wrongAttemptColor;
yield return new WaitForSeconds(blinkDuration);
img.color = original;
SceneManager.LoadScene(previousSceneName);
}
}