Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Accessing image source from script

Discussion in 'UGUI & TextMesh Pro' started by SpiritEvil, Aug 22, 2014.

  1. SpiritEvil


    Nov 28, 2012
    Hi guys. So I've been messing with the new UI for a few hours and I'm trying to make an inventory system. So far everything has been going smoothly except for one very simple thing. I can't seem to find the name of the property that corresponds to the image source, which I'm trying to access via a script. I tried different things such as "image", "imageSource", "texture" but so far no luck. Here's the bit of code I'm using, although I don't think it's going to help much

    Code (CSharp):
    1. GameObject newItem = (GameObject)Instantiate(itemPrefab,, Quaternion.identity);
    2. newItem.transform.parent = grid;
    3. newItem.GetComponentInChildren<Image>().image = item.logo;
    EDIT: Nevermind, I found it. It's simply "sprite" :p
    Last edited: Aug 22, 2014
    Tim-C likes this.