Render Material

Hi!

Below is my code, however, I am getting an error suggesting GetComponent();
to fix the ** mat = renderer.material;**

Any Suggestions? I pulled the DIY from this source: Unity Touchscreen Input Tutorial - YouTube

using UnityEngine;
using System.Collections;

public class Button : MonoBehaviour {

public Color defaultColour;
public Color selectedColour;
private Material mat;


void Start() {

    **mat = renderer.material;**
    
}

void OnTouchDown() {
    mat.color = selectedColour;
}

void OnTouchUp()
{
    mat.color = defaultColour;
}

void OnTouchStay()
{
    mat.color = selectedColour;
}

void OnTouchExit()
{
    mat.color = defaultColour;
}

}

I assume that you are getting the error here

**mat = renderer.material;**

I am also assuming that you are using Unity 5

A lot of tutorials were written for Unity 4 and so was this one (Published on Feb 2, 2014).

The property render has been completely removed. Instead use GetComponent() or

mat = GetComponent<Renderer>().material