How do I make a simple Inventory?
Hello, I am very new to unity. I have tried looking at a million videos on this topic. However, the code either goes over my head, or they seem to rush through the code, and implement features that I would not need on this inventory. I am just looking to make a simple inventory that works with a controller. I just want the inventory to hold the items when picked up, and when selected by pressing X on the PS4 controller to either be equipped or used by the player. I have gotten the UI to come up by using the options button on a PS4 controller. I have also made a simple script that I have attached to a game object which displays a pick up message, and destroys the object upon hitting X. here are the scripts for the PickUp, and inventory that I have. any help is much appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUp : MonoBehaviour
{
public GameObject enterText;
public GameObject itemIcon;
bool pickedUp = false;
// Start is called before the first frame update
void Start()
{
enterText.SetActive(false);
if(pickedUp == false)
{
itemIcon.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerStay(Collider player)
{
if (player.gameObject.tag == "Player")
{
enterText.SetActive(true);
if (Input.GetButtonDown("Pickup") &&! pickedUp)
{
pickedUp = true;
Destroy(gameObject);
enterText.SetActive(false);
itemIcon.SetActive(true);
}
}
}
private void OnTriggerExit(Collider player)
{
if (player.gameObject.tag == "Player")
{
enterText.SetActive(false);
}
}
}
here is the inventory. I have also set up to pause the game when the inventory is displayed on the UI.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Inventory : MonoBehaviour
{
public GameObject invTab;
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
// Start is called before the first frame update
void Start()
{
invTab.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("invTab"))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
void Resume()
{
invTab.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
void Pause()
{
invTab.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
public void LoadMenu()
{
Debug.Log("Loading menu..");
}
public void QuitGame()
{
Debug.Log("Quitting Game....");
}
}
Your answer

Follow this Question
Related Questions
Inventory system: Find an empty slot with Array 1 Answer
Inventory system that stores original items rather than representative icons? 1 Answer
Stuck in a while loop inside my inventory 2 Answers
Adding a singleton script to 2 objects makes one of them dissapear. 0 Answers
IPointerExitHandler while holding click 0 Answers