Use a custom class variable as an int?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Stat
{
    [SerializeField]
    private int baseValue;

    public int GetValue ()
    {
        return baseValue;
    } 
}

Basically I made a custom class called Stat.
I made a variable in another script:

namespace SG
{
    public class CharacterStats : MonoBehaviour
    {
        public int maxHealth;
        public int maxMagicPower;
        public Stat maxMeleeDamage;
    }
}

And I want to use the maxMeleeDamage variable in this code:

public class AttackScript : MonoBehaviour
{
    public GameObject HitParticle;
    private GameObject player;
    private int damageDealt;
    public bool melee;
    public bool ranged;
    public bool magic;
    public int magicPowerDrain;
    private Collider enemy;




    private void Start()
    {
        player = GameObject.FindWithTag("Player");

        if(melee)
        {
            damageDealt = player.GetComponent<PlayerStats>().maxMeleeDamage;
        } else if (ranged)
        {
            damageDealt = player.GetComponent<PlayerStats>().maxRangedDamage;
        } else
        {
            damageDealt = player.GetComponent<PlayerStats>().maxMagicDamage;
        }

    }
}

But It says “Cannot implicitly convert Stat to int”. So idk what to do?

In your AttackScript, variable “damageDealt” is of type int. Subsequently, in the Start method you are trying to assign maxMeleeDamage, maxRangeDamage, maxMagicDamage to damageDealt. As I don’t know how PlayerStats looks like, I suppose maxMaleeDamage is of type Stat. So, if you want to assign maxMaleeDamage to damageDealt, you have to use GetValue method:

damageDealt = player.GetComponent<PlayerStats>().maxMeleeDamage.GetValue(); 

If maxRangeDamage, maxMagicDamage are also of type Stat, then you have to modify your script similarly:

damageDealt = player.GetComponent<PlayerStats>().maxRangedDamage.GetValue();

damageDealt = player.GetComponent<PlayerStats>().maxMagicDamage.GetValue();