Hello, I made a piece of code that I want to turn the mesh renderer on and off by pressing f1, f2, etc. But I get two errors that say the same thing. Here is the code:
#pragma strict
private var showThis : GameObject;
function Start(){
showThis = GameObject.Find("Cube");
}
function Update() {
if(Input.GetKeyDown ("f1"))
{
showThis.GetComponent.MeshRenderer = true;
}
else
{
showThis.GetComponent.MeshRenderer = false;
}
}
When you post code with compiler errors, please copy and past the error message from the console into your question. Your issue is because this is not the way you get a component. In addition you don’t have to use GetComponent() to get the Renderer component. Try this instead:
#pragma strict
private var showThis : GameObject;
function Start(){
showThis = GameObject.Find("Cube");
}
function Update() {
if(Input.GetKeyDown (KeyCode.F1)) {
showThis.renderer.enabled = !showThis.renderer.enabled;
}
}