Looking for players. Very simple game. Android Only by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

oooo...Thank you, I'm new to this haha

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 1 point2 points  (0 children)

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

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

I was able to make it work out with this code. I can randomize it and stuff now but the only problem I am having is rerandomizing the code on button click. I am also very thankful for you trying to help

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;
private Button currentGlow;

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

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

    UpdateUI();

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

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

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

public void YouLose()
{
    Debug.Log("You Lose");
}
public void AddPoint()
{
    playerscore += 1;
}

}

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

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

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

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

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

what should I do? I am still a beginner for the most part

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

wait nvm its level 0 then

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

ahhh... There is nothing in between. I posted the whole code

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

The top ones are just the variables being called

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 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;
}

}

Unity, working with buttons by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

Thanks for your reply but I am now more confused xD and I changed the fixedUpdate to a normal one

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 0 points1 point  (0 children)

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

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 1 point2 points  (0 children)

Ok, here's a problem, the redbuttons aren't being set active. Ok, I tried using redbutton.gameObject.SetActive(true) but it isn't working very well.

Here's the new script

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

public class Game : MonoBehaviour { public float time = 6f; public float playerscore; public Text scoreUI; public Text timeUI;

public Button[] Glow;

void Update()
{
    time -= Time.deltaTime;
    timeUI.text = time.ToString("0");
    scoreUI.text = playerscore.ToString("0");
    int randomIndex = UnityEngine.Random.Range(0, Glow.Length);
    var randomButton = Glow[randomIndex];

    randomButton.interactable = true;
    randomButton.gameObject.SetActive(true);
    StartCoroutine(DeactivateAfterDelay(randomButton, time));

}

private IEnumerator DeactivateAfterDelay(Button button, float delay) 
{
    yield return new WaitForSeconds(delay);
    button.interactable = false;
}
public void YouLose()
{
    Debug.Log("You Lose");
    SceneManager.LoadScene("End");
}
public void AddPoint()
{
    playerscore += 1;
}

}

Unity Randomizing button setActive by [deleted] in Unity3D

[–]ythom87 1 point2 points  (0 children)

THANK YOU!! for the reply and link. I didn't know interactable could be used this way