SOLVED -- It appears that I was attempting to reference a struct (vector2) which isn't passed by reference. Therefore the code was variables / list were not reflecting upon one another.
Thanks everyone.
This is the code I'm using. I want to be able to change the variables that the List is referencing and have the list reflect the updated variables without searching through the list and updating it every time. This will make it much easier to update my buffs and what not.
Is this possible?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Buff : MonoBehaviour{
// (Buff Amount, Timer)
Vector2 thrust = new Vector2(1,0);
Vector2 mass = new Vector2(1,0);
Vector2 shield = new Vector2(1,0);
Vector2 armor = new Vector2(1,0);
Vector2 structure = new Vector2(1,0);
Vector2 regen = new Vector2(1,0);
Vector2 explosionRadius = new Vector2(1,0);
Vector2 damage = new Vector2(1,0);
Vector2 disable = new Vector2(0,0);
List<Vector2> buffs = new List<Vector2>();
// Use this for initialization
void Start () {
buffs.Add(thrust);
buffs.Add(mass);
buffs.Add(shield);
buffs.Add(armor);
buffs.Add(structure);
buffs.Add(regen);
buffs.Add(explosionRadius);
buffs.Add(damage);
buffs.Add(disable);
}
// Update is called once per frame
void Update () {
// Makes Regen variable change.
regen[0] = 5;
// Can I make it affect what is in the List of Vector 2's?
foreach (Vector2 buff in buffs)
{
if (buff.magnitude > 1)
UpdateBuff(buff);
}
}
// Therefore this will be called. Then the variable outside can also be updated?
void UpdateBuff(Vector2 inBuff)
{
Debug.Log("Updating Buff: " + inBuff.ToString());
if ((inBuff[1] -= Time.deltaTime) <= 0)
{
inBuff[0] = 1;
inBuff[1] = 0;
}
}