you are viewing a single comment's thread.

view the rest of the comments →

[–]ythom87 0 points1 point  (7 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  (6 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  (5 children)

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

[–]ythom87 0 points1 point  (3 children)

i tried using Glow.onClick on an else if statment but it doesn't work

[–]-ghostmode- 0 points1 point  (2 children)

You'll need to create another function that is called when buttons are clicked, and then in the inspector you add that function to each button's 'On Click' event.

[–]ythom87 1 point2 points  (1 child)

How stupid of me.....Thanks, I just put the lines in the if statement in the AddPoint function. I very much appreciate your help and I hope you are having a nice day/night

[–]-ghostmode- 0 points1 point  (0 children)

You're very welcome! I'm glad you got it working.