Alors voila je viens juste de me lance dans la création de jeux 3D , et j'ai eu 2 erreur que je n'arrive pas a régler si l'un ou l'une de vous peuvent m'aides sa serai avec grand plaisir : )
je suis sur Unity 2021.3.11f1 ( si sa peut aider )
Erreur :
Script :NullReferenceException: Object reference not set to an instance of an object
Inventory.RefreshContent () (at Assets/Scripts/Inventory.cs:47)
Inventory.Start () (at Assets/Scripts/Inventory.cs:21)
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Inventory : MonoBehaviour
{
[SerializeField]
private List<ItemData> content = new List<ItemData>();
[SerializeField]
private GameObject inventoryPanel;
[SerializeField]
private Transform inventorySlotsParent;
const int InventorySize = 24;
private void Start()
{
RefreshContent();//cs21
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.I))
{
inventoryPanel.SetActive(!inventoryPanel.activeSelf);
}
}
public void AddItem(ItemData item)
{
content.Add(item);
RefreshContent();
}
public void CloseInventory()
{
inventoryPanel.SetActive(false);
}
private void RefreshContent()
{
for (int i = 0; i < content.Count; i++)
{
inventorySlotsParent.GetChild(i).GetChild(0).GetComponent<Image>().sprite = content[i].visual;//cs47
}
}
public bool IsFull()
{
return InventorySize == content.Count;
}