Variable always returns null

So I created a class that holds stats for my weapons so I don’t have to pass like 5 or 6 floats to a function when I can just do it in one variable, but there is a problem - It’s always null even though I set that variable up the line above.

Here is the code and my console:

WeaponStats.cs

using UnityEngine;
using System.Collections;

public class WeaponStats : MonoBehaviour {

    public Weapon randomWeapon;

        public Weapon weapon;
        public float fireRate;
        public float damage;
        public float velocity;
        public float accuracy;
        public float range;

        public WeaponStats(Weapon _weapon, float _fireRate, float _damage, float _velocity, float _accuracy, float _range)
        {
            weapon = _weapon;
            fireRate = _fireRate;
            damage = _damage;
            velocity = _velocity;
            accuracy = _accuracy;
            range = _range;
        }
    void Start ()
    {
        WeaponStats stats = new WeaponStats(randomWeapon, 10f, 10f, 10f, 10f, 10f);
        Debug.Log(stats);
    }

}

Check the yellow warning above your debug log in the console, it gives you a hint as to why it is not working. :wink:

1 Like