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

Access renderer/material in Image class

Discussion in 'UGUI & TextMesh Pro' started by Capn_Andy, Oct 7, 2014.

  1. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Does anyone know how I would go about accessing the renderer (or, more specifically, the material) of a New UI "Image" class object?

    <Image>.sprite exists, but there doesn't seem to be an <Image>.renderer or an <Image>.GetComponent<Renderer>() around.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    Code (csharp):
    1.  
    2. <Image>.material
    3.  
     
  3. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    or <Image>.GetComponent<CanvasRenderer>() as doesnt derive from Renderer so wouldnt be found useing Renderer.
     
  4. wgamestom

    wgamestom

    Joined:
    May 25, 2017
    Posts:
    3
    Out of curiousity: why doesn't CanvasRenderer inherit from Renderer?