How to Get Image Components from the children of a GameObject

I’m setting up an inventory screen UI for a game. I wanted to write a function that changes to match the player’s current set of items when you open it up. The way the inventory UI works is that there’s a panel with a set of button objects as children.

46987-screenshot-2015-05-24-233047.png

However I’m having trouble getting to actually select the Image components of those buttons. I can select their transforms using this code:

private var itemSlots = items.GetComponentsInChildren(Transform);

(items is the Items GameObject, set through the inspector)

However when I try to use Image as the component type I’m getting Unknown Identifier errors. Am I trying to navigate the hierarchy wrong or is there some other problem here?

This is a shot in the dark, but have you included the UnityEngine.UI namespace in the source file referencing the Image component?

You should have this at the top:

C#

using UnityEngine.UI;

JS

import UnityEngine.UI;