Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 iAppmaker · Oct 09, 2016 at 05:57 PM · imageruntimeui imagedynamic loading

Add Image dynamically in runtime

I wish to add the image dynamically based on the number of questions in each level. The image is shown for reference. Each correct answer will be marked in green and the wrong one in red. I am new to unity and trying hard to find steps to achieve this.

Any help with an example for this requirement will be a great help.

alt text

capture.png (18.2 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zeronev · Oct 09, 2016 at 06:33 PM

This is a little complicated to do for starters. Try getting more used to Unity and watch the tutorials made by Unity as well, they help a lot!

To achieve this you need to create a Loop to Instantiate all the circles needed, and you need to have a circle Image (Not the full row, only 1)

the "fill" of the circle must be empty, if the answer is correct, change the sprite to green, or use a mask to fill the circle to the desired color.

You need to have some experience with UI and Scripting to achieve this so I recommend starting something more basic.

Good luck and hope you achieve great things. I can help you more if you want to.

Have a nice day!

Comment
Add comment · 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
0

Answer by toddisarockstar · Apr 21, 2017 at 04:36 AM

well...... you pry don't need to actually make any images with code. You just need to drag and drop images into the script and display them in a row. Just for fun since you mentioned it, i made some images from scratch for the example. But im sure you will want to draw some fancy circles in paint. Anyways, run this and just look at the OnGUI part of this script too see how loops are used to assign a row with a corresponding bool array.

     int i;
     int i2;
 
     public Texture2D box1;
     public Texture2D box2;
 
     bool[] swiches;
 
     Texture2D tex;
     float timer;
     void Start () {
         if(box1==null||box2==null){
         swiches= new bool[20];
         box1 = new Texture2D(6,6);
         box2 = new Texture2D(6,6);
         i = 6;
         while(i>0){i--;
         i2=6;
         while(i2>0){i2--;
             //make an image from scratch
 
                 // small simple example with a border
                 if(i==0||i==5||i2==0||i2==5){
                     box1.SetPixel(i,i2,Color.blue);
                     box2.SetPixel(i,i2,Color.black);}
                 else{
                     
                     box1.SetPixel(i,i2,Color.red);
                     box2.SetPixel(i,i2,Color.green);}
         }}
 
         box1.Apply ();
             box2.Apply ();}
 
         tex = box1;
 }
 
     void OnGUI(){
                 // this is how you display a row of images!
                 // made an array of bools to switch the display
                 // this is the only part you will pry actually use!!!! LOL
                 i = swiches.Length;
                 while (i>0) {
                         i--;
             if(swiches[i]){tex=box1;}else{tex=box2;}
                         GUI.DrawTexture (new Rect (Screen.width * i * .05f, Screen.height * .05f, Screen.width * .04f, Screen.width * .04f), tex);
                 }
         }
 
 
     
 
     void Update () {
         // just to keep it moving!
         timer += Time.deltaTime;
         if (timer > 2) {timer=0;
             i=UnityEngine.Random.Range(0,swiches.Length);
             swiches[i]=!swiches[i];
                 }
     
     }
Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing sprite at runtime causes it to stop resizing 1 Answer

Extending UnityEngine.UI.Image and add extra field available in Inspector 0 Answers

How to get solve two or more UI images alphas? 0 Answers

Dynamic loading of Image target using ARKit - Unity3D 0 Answers

How to avoid color multiplication with UI.Graphic.CrossFadeColor? 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