I created an inventory system with Canvas where a script instantiate a number of slots in it. Now i want to create a script that enable/disable the inventory and can block the movement of the player.
But there is a problem: if I start with the inventory disabled, when you toggle it will be without slots… and the odd thing is that slots are created, but they don’t show into the Canvas.
The script is this:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ToggleInventory : MonoBehaviour {
public bool toggleInventory = true;
private PlayerMovement move;
private CameraMouseLook look;
private Canvas canv;
void Start ()
{
GameObject player = GameObject.FindGameObjectWithTag ("Player");
GameObject cam = GameObject.FindGameObjectWithTag ("MainCamera");
move = player.GetComponent<PlayerMovement> ();
look = cam.GetComponent<CameraMouseLook> ();
canv = GetComponent<Canvas> ();
}
void Update ()
{
if (Input.GetButtonDown ("Inventory") && toggleInventory == true)
{
canv.enabled = !canv.enabled;
move.playerBlocked = !move.playerBlocked;
look.blockCamera = !look.blockCamera;
}
}
}
Anyone help?