- Home /
Question by
Montecristo13 · Oct 02, 2016 at 05:38 AM ·
scripting problemcontrollercs
Controller script problem
Hi,
I've attached a iCade controller script to my FPSController. 3 of 4 joystick axes work. But I still get the following warning:
UnityException: Find is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'iCadeInput' on game object 'FPSController'. See "Script Serialization" page in the Unity Manual for further details. iCadeInput..cctor () (at Assets/iCadeInput.cs:404) Rethrow as TypeInitializationException: An exception was thrown by the type initializer for iCadeInput
Does this mean this portion of my script has to be changed?
/// <summary>
/// Creates an iCade Manager gameobject in the scene, if one doesn't exist. Sets it as DontDestroyOnLoad.
/// </summary>
static iCadeInput()
{
GameObject iCadeManagerGO = GameObject.Find("iCade Manager");
if (iCadeManagerGO == null)
{
iCadeManagerGO = new GameObject("iCade Manager");
Object.DontDestroyOnLoad(iCadeManagerGO);
iCadeManagerGO.AddComponent(typeof (iCadeInput));
}
}
Thanks,
Georg
Comment