Alright I've been writing C/C++ code for a few years but recently got into helping make an indie game with a few guys. We are scripting in C# but i'm just a bit lost on how to do some stuff without pointers.
Its a generic class that holds the non-work portion of a buff. So if I want to buff a character I make a Buff<Character> and assign an Action<Character> to the apply and remove parts. Should work fine in that regard, but thing is I want the buff to keep a
reference to its parent so I can get it back when its time to remove it and apply the "RemoveBuff" logic. Only thing I can think of is have the Buff create an event that the character class that holds it recognizes with an index and removes it, but that seems like a large workaround for what one single pointer could do.
[System.Serializable]
public class Buff<T>
{
T Parent;
//Protected Members
public string Name;
public string SubName;
public string ToolTip;
protected float InternalTimer;
public bool Forever;
public bool Active;
//Public Variables
public Texture2D Icon;
public Action<T> ApplyBuff;
public Action<T> RemoveBuff;
public float Duration;
//Get Time remaining - Read Only
public float TimeLeft
{
get { return InternalTimer; }
}
public void Update()
{
InternalTimer -= Time.deltaTime;
if (InternalTimer <= 0)
{
InternalTimer = 0;
RemoveBuff(Parent);
}
}
}