using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson;
public class InputEnabler : MonoBehaviour {
static FirstPersonController FPSChar;
// Use this for initialization
void Start ()
{
FPSChar = GameObject.FindObjectOfType<FirstPersonController>();
Disable();
}
public static void Disable() // disabling cursor and enabling movement
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
FPSChar.enabled = true;
}
public static void Enable() // enabling cursor and movement
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
FPSChar.enabled = false;
}
}
using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour {
public GameObject inventory;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if(inventory.activeSelf)
{
if(Input.GetKeyDown(KeyCode.I))
//Disable Inventory
inventory.SetActive(false);
InputEnabler.Disable();
}
else
{
if(Input.GetKeyDown(KeyCode.I))
{
//Emable Inventory
inventory.SetActive(true);
InputEnabler.Enable();
}
}
}
}
You have neither declared InputEnabler or gotten a reference to it in your Inventory inventory class.
In Inventory.cs you need to do one of two things, this is the easiest
public InputEnabler inputEnabler;
void Start ()
{
if (inputEnabler == null)
{
Debug.LogError("There is no InputEnabler component set in the inspector. Please set one.");
}
}
otherwise you can do this
private InputEnabler inputEnabler;
void Start ()
{
inputEnabler = GetComponent<InputEnabler>();
if (inputEnabler == null)
{
Debug.LogError("There is no InputEnabler component attached. Please attach one.");
}
}
Now you need to make these changes
InputEnabler.Disable();
and this
InputEnabler.Enable();
to this
inputEnabler.Disable();
this and
inputEnabler.Enable();