Currently I have this StatValue class with only one variable and its purpose is for other classes to use it as the main source of a float value.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class StatValue
{
[SerializeField] private float baseStat;
public float getValue()
{
return baseStat;
}
public float modifyValue(float v)
{
baseStat += v;
return baseStat;
}
}
The class Character_Info for example creates 4 different stats using StatValue class Hp, MS, morale and def under the header Character Stat as oppose to using the float variables within this class itself under the header Remember Stat. This class will be used for different enemies and allies alike.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Character_Info : MonoBehaviour
{
[SerializeField] private Race characterRace;
bool isDead;
[Header("Character Stat")]
[SerializeField] StatValue HP;
[SerializeField] StatValue movementSpeed;
[SerializeField] StatValue morale;
[SerializeField] StatValue def;
[Header("Remember Stat")]
[SerializeField] float r_HP;
[SerializeField] float r_movementSpeed;
[SerializeField] float r_morale;
[SerializeField] float def;
private void Update()
{
if (HP.getValue() <= 0)
{
isDead = true;
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
dealDamageToCharacter();
}
private void dealDamageToCharacter()
{
if (!isDead)
{
HP.modifyValue(-4.0f);
Debug.Log("take damage");
}
}
}
}
My question here is, is there any benefit or downside to continuously use the StatValue class as my main float variable compare to creating 4 different floats under the Remember Stat? Is using this method more efficient in terms of performance?