Added basic logic to minigame, functional flashing by coroutine, Changes mainly in code
This commit is contained in:
41
Assets/Scripts/ButtonsMinigame.cs
Normal file
41
Assets/Scripts/ButtonsMinigame.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ButtonsMinigame : MonoBehaviour
|
||||
{
|
||||
public Light[] lights;
|
||||
public int round = 1;
|
||||
public float glowDuration = 0.4f;
|
||||
public float gapBetween = 0.15f;
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user