Unity C# Problems
I get this error: An object reference is required to access non-static
member `Inventory.ItemID'
I want to change ItemID in Inventory to 1.
ItemSwordUneq
using UnityEngine;
using System.Collections;
public class ItemSwordUneq : MonoBehaviour
{
public bool canPickup = false;
void Start ()
{
}
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;
void Start ()
{
}
void Update ()
{
}
}
What am I doing wrong? Any answers will be appreciated.
No comments:
Post a Comment