Finding an exact child and its exact component

I have this button that has a image as a child along with a text object. So I need the script to change its Alpha channel.

Like this

private Material matt;

Void Awake ()
{
matt = gameObject.GetCommponentFromChild <Material> ();

}

But just how do I get that GetCommponentFromChild with a specified child. And I will not do a gameObject.Find

One that is frowned apon and also I will have more than one object like that with that name.

The child is called Image and I just want to change its alpha.

parentgameobject.transform.GetChild(0).GetComponent(Material);

0 is the first child under parent :wink: hope it helps .

@SciGuy2000

private Material alpha;

private void Start()
{
alpha = this.transform.GetChild(0).GetComponent<Renderer>().material.alpha;
}

Remember that Alpha is a float clamped between [0, 1] so you’ll need to take that into account when writing your script to change it.

If there’s anything you’re unsure about let me know and I’ll be happy to help out.

I figured it out. Sorry. But if this is what others need this is what I did.

public CanvasGroup cann;

void Awake ()
{
     cann = GetComponentInChildren <CanvasGroup> ();
}