Advertisement
evelynshilosky

InventorySystem - Part 5

Jun 2nd, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class InventorySystem : MonoBehaviour
  7. {
  8.  
  9.    public static InventorySystem Instance { get; set; }
  10.  
  11.     public GameObject inventoryScreenUI;
  12.     public bool isOpen;
  13.  
  14.  
  15.     private void Awake()
  16.     {
  17.         if (Instance != null && Instance != this)
  18.         {
  19.             Destroy(gameObject);
  20.         }
  21.         else
  22.         {
  23.             Instance = this;
  24.         }
  25.     }
  26.  
  27.  
  28.     void Start()
  29.     {
  30.         isOpen = false;
  31.     }
  32.  
  33.  
  34.     void Update()
  35.     {
  36.  
  37.         if (Input.GetKeyDown(KeyCode.I) && !isOpen)
  38.         {
  39.            
  40.             Debug.Log("i is pressed");
  41.             inventoryScreenUI.SetActive(true);
  42.             Cursor.lockState = CursorLockMode.None;
  43.             isOpen = true;
  44.  
  45.         }
  46.         else if (Input.GetKeyDown(KeyCode.I) && isOpen)
  47.         {
  48.             inventoryScreenUI.SetActive(false);
  49.             Cursor.lockState = CursorLockMode.Locked;
  50.             isOpen = false;
  51.         }
  52.     }
  53.  
  54. }
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement