61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public enum GameState
|
|
{
|
|
Idle,
|
|
ShowingSequance,
|
|
PlayerTurn,
|
|
GameOver
|
|
}
|
|
|
|
public class ButtonsMinigame : MonoBehaviour
|
|
{
|
|
public Light[] lights;
|
|
public int round = 1;
|
|
public float glowDuration = 0.4f;
|
|
public float gapBetween = 0.15f;
|
|
private int playerStep = 0;
|
|
private GameState state = GameState.Idle;
|
|
private List<int> sequence = new List<int>();
|
|
|
|
void GenerateSequence()
|
|
{
|
|
sequence.Clear();
|
|
for (int i = 0; i < round; i++)
|
|
{
|
|
int randomButton = Random.Range(0,5);
|
|
sequence.Add(randomButton);
|
|
}
|
|
}
|
|
|
|
IEnumerator PlaySequence()
|
|
{
|
|
for (int i = 0; i < sequence.Count; i++)
|
|
{
|
|
int buttonIndex = sequence[i];
|
|
lights[buttonIndex].gameObject.SetActive(true);
|
|
yield return new WaitForSeconds (glowDuration);
|
|
lights[buttonIndex].gameObject.SetActive(false);
|
|
yield return new WaitForSeconds (gapBetween);
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
GenerateSequence();
|
|
StartCoroutine(PlaySequence());
|
|
}
|
|
|
|
void SetState(GameState newState)
|
|
{
|
|
state = newState;
|
|
}
|
|
public void OnButtonClicked(int buttonIndex)
|
|
{
|
|
Debug.Log("Clicked : " + buttonIndex);
|
|
}
|
|
|
|
}
|