我收到此错误:
访问非静态成员“Inventory.ItemID”需要对象引用
我想改成1 ItemID
。Inventory
班级ItemSwordUneq
:
using UnityEngine;
using System.Collections;
public class ItemSwordUneq : MonoBehaviour
{
public bool canPickup = false;
void Update ()
{
if(canPickup == true && Input.GetKeyDown(KeyCode.F))
{
GameObject player = GameObject.Find("Player");
Inventory inventory = player.GetComponent<Inventory>();
Inventory.ItemID = 1;
Destroy(gameObject);
}
}
void OnTriggerEnter(Collider other)
{
canPickup = true;
}
void OnTriggerExit(Collider other)
{
canPickup = false;
}
void OnGUI()
{
if(canPickup == true)
{
GUI.Label(new Rect(250, 250, 300, 20), "Press 'F' To Pick Up Sword");
}
}
}
班级Inventory
:
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour
{
public bool hasItem = false;
public int ItemID;
}
我究竟做错了什么?任何答案将不胜感激。