This is my struct
public struct Timer
{
private readonly float _duration;
public float Time { get; private set; }
public Timer(float duration)
{
_duration = duration;
Time = duration;
}
public void Tick(float deltaTime)
{
if (Time == 0)
return;
Time -= deltaTime;
if (Time < 0)
Time = 0;
}
public void Reset()
{
Time = _duration;
}
}
It can be used by a class like so
public class Level : MonoBehavior
{
private Timer _timer = new Timer(10f);
private void Update()
{
_timer.Tick();
if (_timer.Time == 0)
{
print("Time's up!");
}
}
}
Since the struct only contains value types, does that mean it will automatically be allocated to the stack when it gets instantiated by the other class?