Я хочу получить доступ к переменной * stati c. Я исправляю некоторые, но некоторые все еще ошибки. Вот код, который имеет значение stati c:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Slot : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
static public bool hovered;
static public int SlotNum;
static public GameObject item;
static public int ID;
static public string Type;
static public string Desc;
static public bool empty;
static public Transform SlotIconGO;
static public Sprite Icon;
static public Sprite Transparent;
public GameObject Player;
public void OnPointerEnter(PointerEventData eventData)
{
hovered = true;
}
public void OnPointerExit(PointerEventData eventData)
{
hovered = false;
}
public void OnPointerClick(PointerEventData pointerEventData)
{
UseItem();
}
private void Start()
{
hovered = false;
SlotNum = int.Parse(this.name);
print("SlotNum for slot " + this.name + " = " + SlotNum);
SlotIconGO = transform.GetChild(0);
Icon = Transparent;
}
public void Update()
{
UpdateSlot();
}
public void UpdateSlot()
{
SlotIconGO.GetComponent<Image>().sprite = Icon;
}
public void UseItem()
{
GuyAnimation GrnAni = Player.GetComponent<GuyAnimation>();
GrnAni.GiveWeaponID(ID);
item.GetComponent<Item>().ItemUsage(SlotNum);
}
}
Этот код пытается получить доступ к переменной stati c, но не может:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Inventory : MonoBehaviour
{
public bool InventoryEnabled;
public GameObject inventory;
public GameObject Slotsholder;
public GameObject WM;
static public float Health = 1;
[HideInInspector]
public int AllSlots;
public GameObject[] Slotv { get; private set; }
private int EnabledSlots;
public void Start()
{
AllSlots = 55;
Slotv = new GameObject[AllSlots];
for(int a = 0; a < AllSlots; a++)
{
Slotv[a] = Slotsholder.transform.GetChild(a).gameObject;
if (Slotv[a].GetComponent<Slot>().item == null)
{
Slotv[a].GetComponent<Slot>().empty = true;
}
}
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
InventoryEnabled = !InventoryEnabled;
}
if(InventoryEnabled == true)
{
inventory.SetActive(true);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
else
{
inventory.SetActive(false);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
public void OnTriggerEnter(Collider other)
{
if(other.tag == "Item")
{
GameObject IPU = other.gameObject;
Item item = IPU.GetComponent<Item>();
AddItem(item.Type, item.Desc, item.ID, item.Icon, IPU);
}
}
void AddItem(string type, string desc, int id, Sprite icon, GameObject Object)
{
for(int a = 0; a < AllSlots; a++)
{
if (Slotv[a].GetComponent<Slot>().empty)
{
Object.GetComponent<Item>().PickedUp = true;
Slotv[a].GetComponent<Slot>().item = Object;
Slotv[a].GetComponent<Slot>().Icon = icon;
Slotv[a].GetComponent<Slot>().Type = type;
Slotv[a].GetComponent<Slot>().ID = id;
Slotv[a].GetComponent<Slot>().Desc = desc;
Object.transform.parent = Slotv[a].transform;
Object.SetActive(false);
Slotv[a].GetComponent<Slot>().UpdateSlot();
Slotv[a].GetComponent<Slot>().empty = false;
return;
}
}
}
}
Здесь полная ошибка
error CS0176: Member 'Slot.Icon' cannot be accessed with an instance reference; qualify it with a type name instead
error CS0176: Member 'Slot.item' cannot be accessed with an instance reference; qualify it with a type name instead
error CS0176: Member 'Slot.Type' cannot be accessed with an instance reference; qualify it with a type name instead
error CS0176: Member 'Slot.Desc' cannot be accessed with an instance reference; qualify it with a type name instead
error CS0176: Member 'Slot.ID' cannot be accessed with an instance reference; qualify it with a type name instead
error CS0176: Member 'Slot.Icon' cannot be accessed with an instance reference; qualify it with a type name instead
Как это исправить?