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
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 () {
}
}