So here is the relevant code:
void Update () {
//t += Time.deltaTime;
//print(t);
renderer.material.color = Color.Lerp(start, end, 5);
if (renderer.material.color.a <= 0.0)
Destroy(gameObject);
}
So I don’t get why it’s giving the IndexOutOfRange exception. I’m most certainly sure that it’s the number I give it(5 in this case). I have even tried putting an f after the numner(like 5f) to make sure it’s a float but to no avail. Any clarification would be really helpful. Maybe I’m just not understanding Lerp enough.
Edit: So I noticed that this isn’t all the relevant code. The exception is actually happening in a whole different class which is this one:
public class RandomSprite : MonoBehaviour {
public Sprite[] sprites;
public string resourceName;
public int currentSprite = -1;
// Use this for initialization
void Start () {
if (resourceName != "") {
sprites = Resources.LoadAll<Sprite>(resourceName);
if (currentSprite == -1)
currentSprite = Random.Range(0, sprites.Length);
else if (currentSprite > sprites.Length)
currentSprite = sprites.Length - 1;
**GetComponent<SpriteRenderer>().sprite = sprites[currentSprite];**
}
}
The line within the asterisks … is the line that the error is pointing to.