(sorry for everything lowercase, the shift on my keyboard is kinda stuck(u know how hard its to script that way?))
lately i decided to implement simple inventory system in my game. i created a simple image in paint.net that resembles thing i wanted to have. then i applied it to canvas. for every slot in this inventory i made a raw image with collider, and a counter thats a child of the image. works fine so far. then i made a script for it like this(not done yet)
using UnityEngine;
using System.Collections;
public class inwentarz : MonoBehaviour {
public GameObject eq; // whole inventory object
public bool czyEqWidoczne = false;
public bool czyMyszWolna = false;
public Texture[] itemyTeksturki; // item textures
private Texture[] itemyWEqtekstury; //textures of items that are in inventory now
private GameObject[] ObiektIkonyItemu; // array with image objects
private int[] itemyWequ; // the inventory itself
private string TerazPrzypisuje; //so that you can assign textures to arrrays
// ITEM & TEXTURE ids 0-nic 1-lom 2-pistolet 3-aks74u 4-jagody 5-kokosy 6-banany 7-magazynkiMakarow 8-magazynkiAKS74u 9-LeczniczeLiscie
void Start(){
for(int i = 0; i < 20; i++)
{
TerazPrzypisuje = "Item (" + i.ToString() + ")";
ObiektIkonyItemu *= GameObject.Find("Canvas/Inwentarz/" + TerazPrzypisuje);*
itemyWEqtekstury = ObiektIkonyItemu*.GetComponent().material.mainTexture;*
_ itemyWequ = 0;
* }
//Debug Items*
* itemyWequ[1] = 4;
itemyWequ[3] = 9;
}
void FixedUpdate () {
//Cursor.visible = true;
if(Input.GetKeyDown(KeyCode.Tab))
{
switch(czyEqWidoczne)
{
case false:
czyEqWidoczne = true;
eq.SetActive(true);
czyMyszWolna = true;
break;
case true:
czyEqWidoczne = false;
eq.SetActive(false);
czyMyszWolna = false;
break;
}
}
switch(czyMyszWolna)
{
case false:
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
break;
case true:
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
break;
}
for(int i = 0; i < 20; i++)
{
if(itemyWequ != 0)
{_
itemyWEqtekstury _= itemyTeksturki;
}
}
}
}
the game compiles and runs, but the debug items does not show in the inventory screen and some weird errors appear
NullReferenceException: Object reference not set to an instance of an object
(wrapper stelemref) object:stelemref (object,intptr,object)*
and i dont want to use pre-made inventory systems, because i know i wont learn anything that way. cheers!_