Hi Unity Gurus! I’m new to all this so be gentle with me. I’m working through the site’s tutorials. They’ve been great so far but I’ve moved on to the scripting section only to find Unity4.* outdated code. For example…
using UnityEngine;
using System.Collections;
public class ExampleBehaviourScript : MonoBehaviour
{
void Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.renderer.material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.renderer.material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.renderer.material.color = Color.blue;
}
}
}
The correct way I’ve found with some searching the documentation is as follows…
using UnityEngine;
using System.Collections;
public class Color : MonoBehaviour
{
void Update ()
{
if(Input.GetKeyDown(KeyCode.R))
{
gameObject.GetComponent<Renderer>().material.color = Color.red;
}
if(Input.GetKeyDown(KeyCode.G))
{
gameObject.GetComponent<Renderer>().material.color = Color.green;
}
if(Input.GetKeyDown(KeyCode.B))
{
gameObject.GetComponent<Renderer>().material.color = Color.blue;
}
}
}
However, the terms “red” , “green” and “blue” are returning the error - CSO117: “Color” does not contain a definition for “red”.
Considering the updated code was a copy and paste I’m assuming I’ve missed something simple in all my newb glory. To any replies thanks in advance!