I want to change fill amount of the image.This image in the button.

The code is here
int correctRate = Random.Range(50, 90);
GameObject.Find("Correct").GetComponentInChildren<Image>().fillAmount = correctRate * 0.01f;
GameObject.Find("Wrong"+"1").GetComponentInChildren<Image>().fillAmount = Random.Range(5, 55) * 0.01f;
GameObject.Find("Wrong"+"2").GetComponentInChildren<Image>().fillAmount = Random.Range(5, 66) * 0.01f;
GameObject.Find("Wrong"+"3").GetComponentInChildren<Image>().fillAmount = Random.Range(5, 66) * 0.01f;
It does not effect fill amount.How can i do that ?
P.s
Image type : Filled
Fill Method : Horizontal
Fill Origin : Left
Fill Amount :0
It does not work because you dont have 1 children. GetComponentInChildren() → which children?
I think this is the problem but i wouldn’t do that way. I would create a public Image inside the script and then from the inspector set the object “Image” then do all the stuff on this variable
The problem is that I can not use to create a public Image because the game objects are created by Instantiate method
So if you want to access to the components of the instantiated object do:
var obj = Instantiate(yourObject…)
obj.GetComponent()
I found out a solution like this.
GameObject.Find("Correct").transform.GetChild(0).GetComponentInChildren<Image>().fillAmount = correctRate * 0.01f;
GameObject.Find("Wrong" + "1").transform.GetChild(0).GetComponentInChildren<Image>().fillAmount = Random.Range(5, 55) * 0.01f;