如您所见,一切都设置为公开,但编译器说:
Shooting.inventoryWeapon.inventoryWeapon(Shooting.weapon, int)
由于其保护级别而无法访问。
此代码在射击类中。
public enum weapon{gun,shotgun};
public struct inventoryWeapon{
weapon current;
int shotAmmo;
inventoryWeapon(weapon cur,int shAmmo){
current=cur;
shotAmmo=shAmmo;
}
}
public inventoryWeapon[] Inventory;
int weaponIndex=0;
void Start(){
Inventory=new inventoryWeapon[10];
Inventory[weaponIndex]= new inventoryWeapon(weapon.shotgun,30);
}