So this isn’t a game breaking error, however i would like these errors to be gone by the time we build and currently this is the only one and I’m not sure what to do with it. The script is set up to put an inventory GUI on an active camera. the game we’re making is akin to old school survival horrors with the fixed camera system like Fatal Frame, and the old Resident Evil games. So if someone can point out a better way to do this I would be greatly appreciative.
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
PlayerMapInventory…ctor ()
UnityEngine.GameObject:AddComponent()
ActivateTriggerCamera:OnTriggerEnter(Collider) (at Assets/Scripts/ActivateTriggerCamera.cs:39)
enter code hereusing UnityEngine;
using System.Collections;
public class ActivateTriggerCamera : MonoBehaviour
{
#region Editor Variables
public GameObject TriggerCamera = null;
public bool DebugScript = false;
private GameObject CurrentMainCamera = null;
#endregion
#region Public Methods
public void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
if(CurrentMainCamera == null)
{
CurrentMainCamera = GameObject.FindWithTag("MainCamera");
CurrentMainCamera.tag = "Untagged";
CurrentMainCamera.SetActive(false);
PlayerMapInventory inventory = CurrentMainCamera.gameObject.GetComponent<PlayerMapInventory>();
if(inventory == null)
{
Destroy(inventory);
}
CurrentMainCamera = null;
TriggerCamera.tag = "MainCamera";
TriggerCamera.SetActive(true);
inventory = TriggerCamera.gameObject.GetComponent<PlayerMapInventory>();
if(inventory == null)
{
TriggerCamera.gameObject.AddComponent<PlayerMapInventory>();
}
}
else
{
if(DebugScript == true)
{
Debug.Log("The current main camera is the same as the trigger's camera.");
}
}
}
else
{
if(DebugScript == true)
{
Debug.Log("Something other than the player entered " + gameObject.name + ".");
}
}
}
#endregion
}