Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JA_555 · Aug 23, 2014 at 04:50 PM · randomguitexture

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Aug 23, 2014 at 05:00 PM 0
Share

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.

avatar image JA_555 · Aug 23, 2014 at 06:51 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Aug 23, 2014 at 05:15 PM 0
Share

@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.

avatar image TRG96 · Aug 23, 2014 at 08:15 PM 0
Share

ahh /i see. then there must be a problem where he is drawing the textures

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

two Random.Range returning similar values 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges