- Home /
Event Tutorial Question: renderer.material
I'm following the scripting event tutorial on Unity (https://unity3d.com/learn/tutorials/topics/scripting/events)
However, I get the following error on my renderer.material.color ref. (I was able to successfully script the random teleport of a game object)
Assets/_Scripts/TeleportBox.cs(24,18): error CS1061: Type UnityEngine.Component' does not contain a definition for
material' and no extension method material' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
This is what I have in my script: Color col = new Color(Random.value, Random.value, Random.value); renderer.material.color = col;
Answer by Hellium · Jun 08, 2017 at 07:02 AM
The components must be accessed using the GetComponent function:
void TurnColor()
{
Color col = new Color(Random.value, Random.value, Random.value);
GetComponent<MeshRenderer>().material.color = col;
}
The getters like renderer
, transform
, collider
, rigidbody
, light
, ... will be depreciated and should not be used anymore
Your answer

Follow this Question
Related Questions
Tree Chopping & Transforming 2 Answers
3d Game Kit ( Grenadier) 0 Answers
changing between character controllers 1 Answer
How to keep my health bar directly above my player and straight no matter how the player turns? 3 Answers
How should I code for multiple types of enemy with specific action set? 1 Answer