Hide image control

I’m trying to hide an image control through code, but it’s not working.
I’ve tried the following code:
ImageT.GetComponent().enabled = false;

but I get a runtime error saying:
There is no ‘Renderer’ attached to the “ImageT” game object, but a script is trying to access it.

If you are using the new UI, I think you need to get the Canvas not Renderer and disabled that. Failing that set the images alpha property to full transparent - 1.0

It’s telling you the gameObject this script is on or whatever imageT is doesn’t have a Render component…Does the object have a mesh render?

Thank you all for your answers.
No, SubZeroGaming, it doesn’t.

That’s the issue. You can’t access a property of a component if it doesn’t exist. If you are working with the new UI, grab the Image component and then set enable to false. Not the Render.

Yes, I’m working with the new UI.
How do you mean “grab the Image component and then set enable to false”?
Like this?
ImageT.GetComponent().enabled=false;
or like this?
ImageT.enabled=false;

Both dont work.
This is my code:

using UnityEngine;
using System.Collections;

public class Script_TestResizeAgain : MonoBehaviour {
    private GameObject PlaneT;
    private GameObject ImageT;
 

    void Start () {

        PlaneT=GameObject.Find("PlaneT");
        ImageT=GameObject.Find("ImageT");
      
        PlaneT.transform.position=ImageT.transform.position;
        PlaneT.transform.localScale=ImageT.transform.localScale;

        ImageT.GetComponent<Renderer>().enabled = false;
    }  
}

I get the same error with the canvas
MissingComponentException: There is no ‘Renderer’ attached to the “CanvasT” game object, but a script is trying to access it. You probably need to add a Renderer to the game object “CanvasT”. Or your script needs to check if the component is attached before using it

Here is the code

using UnityEngine;
using System.Collections;



public class Script_TestResizeAgain : MonoBehaviour {

    private GameObject PlaneT;
    private GameObject ImageT;
    public GameObject CanvasT;

    // Use this for initialization
    void Start () {
       
        PlaneT=GameObject.Find("PlaneT");
        ImageT=GameObject.Find("ImageT");
        CanvasT=GameObject.Find("CanvasT");
       
        PlaneT.transform.position=ImageT.transform.position;
        PlaneT.transform.localScale=ImageT.transform.localScale;

        CanvasT.GetComponent<Renderer>().enabled=false;
    }
   
    // Update is called once per frame
    void Update () {
       
    }
}

No I meant you need to get the canvas component GetComponent

No, you don’t need the canvas component to turn off an Image…you simply grab the Image…

You need the using unity engine.ui namespace.
Then you need a handle to your Image component.

public Image myImage; //assign it in the inspector.

Then you can do myImage.enabled = false.

or in void start()

Assign the handle. myImage = get component

I’m not going to spoon feed you. Watch my tutorials and learn something.

Thank you all.
It works, like Korno said.