﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Llama : MonoBehaviour {

	float color;
	MaterialPropertyBlock propBlock;
	MeshRenderer rend;

	void Start () {
		propBlock = new MaterialPropertyBlock ();
		rend = GetComponent<MeshRenderer> ();
	}

	void Update () {
		if (!rend)
			return;
		
		// Get the current value of the material properties
		rend.GetPropertyBlock (propBlock, 0);

		// Set the new value
		propBlock.SetColor ("_Color", Color.HSVToRGB (color, 1, 1, true));

		// Apply the new value
		rend.SetPropertyBlock (propBlock, 0);

		if (color >= 1f) {
			color = 0f;
		} else {
			color += 0.0025f;
		}
	}
}
