accepting item in inventory by Lua
Posted: Sat Oct 07, 2023 9:29 am
Hello! I just recently started using the dialogue manager, so I'm still doing stupid things...
So! I'm trying to register items through Lua that I put in my own inventory. I followed the tutorialhttps://www.youtube.com/watch?v=55I0psnQp7Q, but for some reason it doesn't work
I will be glad to receive your help!
So! I'm trying to register items through Lua that I put in my own inventory. I followed the tutorialhttps://www.youtube.com/watch?v=55I0psnQp7Q, but for some reason it doesn't work
I will be glad to receive your help!
Code: Select all
public class Item : MonoBehaviour
{
[SerializeField]
private string itemName;
[SerializeField]
private int quantity;
[SerializeField]
private Sprite sprite;
[TextArea]
[SerializeField]
private string itemDescription;
private InventoryManager inventoryManager;
// Start is called before the first frame update
void Start()
{
inventoryManager = GameObject.Find("InventoryCanvas").GetComponent<InventoryManager>();
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
inventoryManager.AddItem(itemName, quantity, sprite, itemDescription);
Destroy(gameObject);
}
}
private void OnEnable()
{
Lua.RegisterFunction("ItemPicked", this, SymbolExtensions.GetMethodInfo(() => ItemPicked(string.Empty)));
}
private void OnDisable()
{
Lua.UnregisterFunction("ItemPicked");
}
public bool ItemPicked(string name)
{
if (name == "poop") return true;
return false;
}
}