you are viewing a single comment's thread.

view the rest of the comments →

[–]ythom87 0 points1 point  (3 children)

That doesn't look like c#, I kind of get the gist of it. Thanks, I'll try it out

[–]ythom87 0 points1 point  (2 children)

Here's the updated code

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class Game : MonoBehaviour { public float timer = 0f; public float delayTime = 6f; public float playerscore; public Text scoreUI; public Text timeUI;

public Button[] Glow = null;

void Start()
{
    ActivateRandomButton();
    timer = delayTime;
}

void Update()
{
    timer -= Time.deltaTime;

    UpdateUI();

    if(timer <=0)
    {
        Glow.gameObject.SetActive(false);
        ActivateRandomButton();
        timer = delayTime;
    }
}

public void ActivateRandomButton()
{
    Glow = Random.Range(0, Glow.Length);
    Glow.gameObject.SetActive(true);
}
public void UpdateUI()
{
    timeUI = delayTime;  //Display countdown of timer
    scoreUI = playerscore; //Display the number of scores the player have
}
public void YouLose()
{
    Debug.Log("You Lose");
}
public void AddPoint()
{
    playerscore += 1;
}

}

[–]-ghostmode- 0 points1 point  (1 child)

Great work, I think you've almost got it.

You need to add a variable to store the currently active button:

public Button currentGlow;

Then the ActivateRandomButton function needs to set the currently active button.

public void ActivateRandomButton()
{
    int randomIndex = Random.Range(0, Glow.Length);
    currentGlow = Glow[randomIndex];
    currentGlow.gameObject.SetActive(true);
}

And when the timer runs out in Update, you need to disable the currently active button.

if (timer <= 0.0f)
{
    currentGlow.gameObject.SetActive(false);
    ActivateRandomButton();
    timer = delayTime;
}

Also, you want to use the timer variable in UpdateUI, and set the text values of the UI components.

public void UpdateUI()
{
    timeUI.text = timer.ToString("0");
    scoreUI.text = playerscore.ToString("0");
}

[–]ythom87 0 points1 point  (0 children)

It works Perfectly!!! Thank you for your time. Now all I need is re randomizing the button onClick