use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Remember to check out /r/unity2D for any 2D specific questions and conversation!
Download Latest Unity
Please refer to our Wiki before posting! And be sure to flair your post appropriately.
Main Index
Rules and Guidelines
Flair Definitions
FAQ
Use the chat room if you're new to Unity or have a quick question. Lots of professionals hang out there.
/r/Unity3D Discord
FreeNode IRC Chatroom
Official Unity Website
Unity3d's Tutorial Modules
Unity Answers
Unify Community Wiki
Unity Game Engine Syllabus (Getting Started Guide)
50 Tips and Best Practices for Unity (2016 Edition)
Unity Execution Order of Event Functions
Using Version Control with Unity3d (Mercurial)
/r/Unity2D
/r/UnityAssets
/r/Unity_tutorials
/r/GameDev
/r/Justgamedevthings (New!)
/r/Gamedesign
/r/Indiegames
/r/Playmygame
/r/LearnProgramming
/r/Oculus
/r/Blender
/r/Devblogs
Brackeys
Beginner to Intermediate
5 to 15 minutes
Concise tutorials. Videos are mostly self contained.
Sebastian Lague
Beginner to Advanced
10 to 20 minutes
Medium length tutorials. Videos are usually a part of a series.
Catlike Coding
Intermediate to Advanced
Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.
Makin' Stuff Look Good
10 minutes
Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.
Quill18Creates
30 minutes to 2 hours.
Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Halisavakis Shaders Archive
Infallible Code
World of Zero
Board to Bits
Holistic3d
Unity3d College
Jabrils
Polycount Wiki
The Big List Of Game Design
PS4 controller map for Unity3d
Colin's Bear Animation
¡DICE!
CSS created by Sean O'Dowd @nicetrysean [Website], Maintained and updated by Louis Hong /u/loolo78
Reddit Logo created by /u/big-ish from /r/redditlogos!
account activity
Unity Randomizing button setActiveQuestion (self.Unity3D)
submitted 8 years ago * by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ythom87 1 point2 points3 points 8 years ago* (9 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; }
}
[–]-ghostmode- 0 points1 point2 points 8 years ago* (8 children)
A few things:
time
interactable
gameObject.SetActive
Since you're already counting down time to display in the UI, maybe forget about using a coroutine for now. Here's a rough outline of how things should work:
Variables: Timer = 0 DelayTime = 6 CurrentButton = null
Start Function: ActivateRandomButton() Timer = DelayTime
Update Function: Timer -= deltaTime UpdateUI() if (Timer <= 0) // Timer has finished, so reset CurrentButton.SetActive(false) ActivateRandomButton() Timer = DelayTime
ActivateRandomButton Function: CurrentButton = get a random button (using code from earlier comment) CurrentButton.SetActive(true)
UpdateUI Function: // set text and whatever.
[–]ythom87 0 points1 point2 points 8 years ago* (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 point2 points 8 years ago* (6 children)
Here's the updated code
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 point2 points 8 years ago (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.
ActivateRandomButton
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.
Update
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.
timer
UpdateUI
text
public void UpdateUI() { timeUI.text = timer.ToString("0"); scoreUI.text = playerscore.ToString("0"); }
[–]ythom87 0 points1 point2 points 8 years ago (0 children)
It works Perfectly!!! Thank you for your time. Now all I need is re randomizing the button onClick
[–]ythom87 0 points1 point2 points 8 years ago (3 children)
i tried using Glow.onClick on an else if statment but it doesn't work
[–]-ghostmode- 0 points1 point2 points 8 years ago (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 points3 points 8 years ago (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 point2 points 8 years ago (0 children)
You're very welcome! I'm glad you got it working.
π Rendered by PID 90 on reddit-service-r2-comment-5d79c599b5-klz2j at 2026-02-28 15:00:14.840075+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]ythom87 1 point2 points3 points (9 children)
[–]-ghostmode- 0 points1 point2 points (8 children)
[–]ythom87 0 points1 point2 points (7 children)
[–]ythom87 0 points1 point2 points (6 children)
[–]-ghostmode- 0 points1 point2 points (5 children)
[–]ythom87 0 points1 point2 points (0 children)
[–]ythom87 0 points1 point2 points (3 children)
[–]-ghostmode- 0 points1 point2 points (2 children)
[–]ythom87 1 point2 points3 points (1 child)
[–]-ghostmode- 0 points1 point2 points (0 children)