using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WhiteSheep : MonoBehaviour
{
public GameObject sheep;
public GameObject trees;
void Start()
{
int colour = getRandomInt(0, 2);
if (colour == 1)
{
Renderer rend = GetComponent<Renderer>();
//so we can access the colour
rend.material.shader = Shader.Find("_Color");
rend.material.SetColor("_Color", Color.red);
rend.material.shader = Shader.Find("Specular");
rend.material.SetColor("_SpecColor", Color.red);
//Find the Specular shader and change its Color to red
}
else if (colour == 0)
{
Renderer rend = GetComponent<Renderer>();
//so we can access the colour
rend.material.shader = Shader.Find("_Color");
rend.material.SetColor("_Color", Color.blue);
rend.material.shader = Shader.Find("Specular");
rend.material.SetColor("_SpecColor", Color.blue);
}
}
private int getRandomInt(int start, int end)
{
float fRandom = Random.Range(start, end);
int iRandom = Mathf.FloorToInt(fRandom);
return iRandom;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.CompareTag ("Player"))
{
foreach (GameObject tree in trees)
{
Renderer rend = tree.GetComponent<Renderer>();
rend.material.shader = Shader.Find("_Color");
rend.material.SetColor("_Color", Color.magenta);
rend.material.shader = Shader.Find("Specular");
rend.material.SetColor("_SpecColor", Color.magenta);
}
}
}
}
I want to make the colour change to be repeated by using a loop, but when I add a loop into the void Start, it happens too quick that I can’t observe it happening. Is there any way slowing down the loop in Unity?