P
P
Proqon2021-06-28 16:53:21
C++ / C#
Proqon, 2021-06-28 16:53:21

Error CS1061 unity how to fix the error?

error CS1061: 'Inventory' does not contain a definition for 'slots' and no accessible extension method 'slots' accepting a first argument of type 'Inventory' could be found (are you missing a using directive or an assembly reference?)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickup : MonoBehaviour
{
    private Inventory inventory;
    public GameObject slotButton;

    private void Start()
    {
        Inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CampareTag("Player"))
        {
            for (int i = 0; i < inventory.slots.Length; i++)
            {
                if(inventory.isFull[i] == false)
                {
                    inventory.isFull[i] = true;
                    Instantiate(slotButton, inventory.slots[i].transform);
                    Destroy(gameObject);
                    break;
                }
            }
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-06-28
@Proqon

The Inventory class does not have a public field or property named slots.
How to fix it - add such a field, or fix the code where it is accessed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question