Such a simple question, I was sure it’s already answered, but I searched and no, it seems not:
I want my game to have settings where Head Bob, sensitivity, etc. can be configured by the player, but it turns out that the standard assets FPS Controller does not expose these parameters.
Can I change them from a (new) UI control without having to partially re-write the controller script?
If you look in the inspector of your FPSController that is on the scene,
in the component First Person Controller (Script), there is a checkbox for Use Head Bob.
It’s just a matter of making a simple script that will let the players toggle that checkbox.
There are a few twists though… Here is simple solution, you need to:
Assign the script below on a UI Toggle element.
You need to drag and drop your FPSController gameObject in the public field controller.
You need to go inside FirstPersonController.cs and change the m_UsedHeadBob to public.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Characters.FirstPerson; //You need this to access the FirstPerson Controller
using UnityEngine.UI; //You need this to access the UI toggle..
public class ToggleHeadBob : MonoBehaviour
{
public FirstPersonController controller;
Toggle headBobToggle;
void Start ()
{
headBobToggle = GetComponent<Toggle>();
headBobToggle.onValueChanged.AddListener(ToggleBob);
//To make sure the checkbox is set the the status of the headbob.
headBobToggle.isOn = controller.m_UseHeadBob; //FirstPersonController.m_UseHeadBob is a private variable, you need to go in the script and change it to public.
}
void ToggleBob (bool isActive)
{
controller.m_UseHeadBob = isActive;
}
}