Hello all.
I’m trying to change the values of variables based on whether a certain sprite in a list is being used in the Sprite Renderer:
using UnityEngine;
using System.Collections.Generic;
public class Answers : MonoBehavior
{
public List<Sprite> exampleList = new List<Sprite>();
public float valueToChange;
public int ID;
private Rigidbody2D rb;
private SpriteRenderer sr;
void Start()
{
rb = GetComponent<Rigidbody2D>();
sr = GetComponent<SpriteRenderer>();
exampleList[ID] = sr.sprite;
}
void FixedUpdate();
{
if (sr.sprite = exampleList[0])
valueToChange = 3.2f;
rb.mass = 1.5f;
if (sr.sprite = exampleList[1])
valueToChange = 6.1f;
rb.mass = 0.3f;
//... and so on
}
}
The issue I’m having is that this always returns the last sprite in the list and uses its values, regardless of what I set the ID value to.
I’m still very much a beginner so it might be that I’m just overlooking something.
Thanks!