- Home /
Question by
Sushi_Cat · Jun 11, 2015 at 05:03 PM ·
c#gameobject
renderer.material function wont work.
I've been following a Unity tutorial published by unity word for word but some of his code is giving me errors. It's probably the new version or something but I need some help. Here's my code. using UnityEngine; using System.Collections;
public class ColorChanger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.R)) {
gameObject.renderer.material.color = Color.red;
}
}
}
The material.color is highlighted red and it give me errors. Why?
Comment
Answer by Hiten2012 · Jun 11, 2015 at 05:45 PM
its up to which version of unity your are using, if its unity 5 than its like
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
gameObject.GetComponent<Renderer>().material.color = Color.red;
}
}