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.

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!

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*){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_=!swiches*;
}*_

* }*