- Home /
How to randomize and then display a GUITexture
Hello, I am currently modifying this script to choose a random texture and then display it. This is a script from user tbkn that I partly understand
public GUITexture[] possibleChoices = new GUITexture[0];
public GUITexture getRandomGUITexture() {
return possibleChoices[Random.Range(0, possibleChoices.Length)];
So far, I understand that it is supposed to get a list of items in the inspector. Then it is supposed to choose one of those with the 0.possibleChoices.Length. What I don't understand is why the texture is not displaying.
thanks
Selecting a GUITexture from an array does not show that GUITexture. Are the textures disabled? Are they positioned off the screen? Are they stacked so that one GUITexture hides another? You will have to do something to make it show, but we need to know what was done to the texture to make it not show.
I had another script to disable all the textures, and then I wanted to use the randomizer script to display a random texture. The other script is as follows:
var button : GUITexture;
var button2 : GUITexture;
function Start(){
Button.enabled = false;
Button2.enabled = false;
I decided to remove this disabler script, but now the textures just show up at once, so I don't know which is the random one. I need a way of enabling and displaying just the one random texture.
Answer by TRG96 · Aug 23, 2014 at 05:07 PM
You are making an array and setting the array size to 0, the array doesnt have any textures inside it, its just an empty array with size 0. You can use
possibleChoices[Random.Range(0, 10]
which will return a number between 0 and 10 and you can make an array and put some GUITextures inside it and based on which random number was chosen you can get a texture from the array and draw it. How are you drawing the textures, need to see the code.
@TRG96 - setting the array size is not the issue. That line of code is only executed when the script is attached and would be overridden by any changes made in the Inspector. So if he changed the size of the array in the Inspector and dragged GUITextures into the slots, his code will select one of the GUITextures.
ahh /i see. then there must be a problem where he is drawing the textures
Your answer
Follow this Question
Related Questions
Kinect Dance Game Unity3d 2 Answers
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Help with Generating Random Tiles 1 Answer
Random time interval 1 Answer