Struct Error CS0122

I’m testing out Structs in Unity by making a Public Struct containing 3 int variables and then try assigning a value to each in the Start method. The problem is that I am getting a CS0122 error stating “`variable’ is inaccessible due to its protection level”.

What is the problem here and how can I fix it? I’ve put the code bellow. Please Help!

Thanks!

Code:

using UnityEngine;
using System.Collections;
using System;

public class Weapons : MonoBehaviour {

public struct WeaponSelect {

	int weapon;
	int ammo;
	int maxAmmo;

}

// Use this for initialization
void Start () {

	WeaponSelect.weapon = 1; 
	WeaponSelect.ammo = 30; 
	WeaponSelect.maxAmmo = 200;
}
1 Like

You need to make the variables inside the class public:

public struct WeaponSelect {
 
    public int weapon;
    public int ammo;
    public int maxAmmo;    
}