Hello, I am instantiating a sprite into my game, and at first I want to give it a random color, but as the next sprite spawns I want the color to change a tiny amount. I have a small bit of code that chooses a random color nicely, but when I try changing the color on the next sprite, it goes back to the original sprite color. Any help is appreciated thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawner : MonoBehaviour {
public GameObject circle;
public float shrinkRate;
public static bool canSpawn = true;
private Color customColor;
// Use this for initialization
void Start () {
chooseRandomColor ();
}
// Update is called once per frame
void Update () {
if (canSpawn == true) {
canSpawn = false;
var circleVector = new Vector3 (0, 0, 0);
var circleInstance = Instantiate (circle, circleVector, Quaternion.Euler(0, 0, Random.Range(0.0f, 360.0f)));
customColor.r = customColor.r + 1f;
customColor.g = customColor.g + 1f;
customColor.b = customColor.b + 1f;
circleInstance.GetComponent<SpriteRenderer> ().color = customColor;
}
}
void chooseRandomColor () {
customColor = new Color (Random.value, Random.value, Random.value);
}
}