Access to new First Person Controller

Hi,
I’m using FirstPersonController from Unity 5 standard assets. In other script i have player stats (hp, stamina etc.). And I want to be able to disable “run” option from FPC if stamina is <= 0.

And here is the question: How can I access to params in FPC if every is private and there is no public functions. If this is possible or only way is to modify FPC?

In Unity 5 if you’re using the first person controller, you will probably want to create a new private variable called ‘m_CanRun’ as type bool and set it to your default true or false.

Then you can create a public property to interact with this new private backing field(the backing field isn’t necessary but).

new in the class definition:

// .. other unity privates
private bool m_CanRun = true; // not sure if this is the correct assumption.
// .. other unity code

public bool CanRun
{
	get { return m_CanRun; }
	set { m_CanRun = value; }
}

You will find a line that is a ternary that modifies the speed based off m_IsWalking, it should look like:

speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed; // about line 217

Modify this to:

speed = m_IsWalking ? m_WalkSpeed : m_CanRun ? m_RunSpeed : m_WalkSpeed;

this basically says…

if m_IsWalking is true, then use m_WalkSpeed

If m_IsWalking is false, then if m_CanRun is true, then use m_RunSpeed, otherwise use m_WalkSpeed

You can now interact with the public property CanRun when getting a reference to this Component and modify it’s boolean value depending on your staminia.