Find UI image game objects

Having a bit of trouble with this…

I have three game objects (statusBar1, statusBar2, statusBar3) on a canvas, each using a certain image. I want to use a single script to adjust the fillAmount of the objects in different ways. How do I find the specific game objects instead of just the Image component?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class StatusBar : MonoBehaviour
{
    Image statusBar;
  
    void Start ()
    {
        statusBar = GetComponent<Image>();
      
        // find gameobject with name statusBar1
        // find gameobject with name statusBar2
        // find gameobject with name statusBar3
    }
  

    void Update ()
    {
        statusBar1.fillAmount = something
        statusBar2.fillAmount = somethingElse
        statusBar3.fillAmount = somethingElseAgain
    }
}

Heres is what i do when i activate/unactivate canvas for example the main menu

    private Canvas canvas;
   
    void Start()
    {
        GameObject go = GameObject.Find("MainMenu");
        if (!go)
            return;
       
        canvas = go.GetComponent<Canvas>();
    }
   
    public void ClickButton(string buttonID)
    {
        if (canvas)
            canvas.enabled = !canvas.enabled;
    }
}
1 Like