Get variable from seconds script not working

Getting a variable from a different script.

I included 2 files
I use the prefab in the unity standard assets first person ridgid body controller and am attempting in to edit it to check for when a player stamina reaches 0 to then disable the “Left Shift” Run key until Stamina regenerates. The script that needs a variable to continue working is posted first and second is the script that handles the stamina.

I am having issues getting a variable from GUISurvival.js

Starting on Line 49 In the RidgidbodyFirstPersonController.cs are the changes I have made. Line 49 is labeled //LINE 49 starts here>>>>>>>>>>>>>>>>>>>> to make it easier to find.

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets.Characters.FirstPerson
{
    [RequireComponent(typeof (Rigidbody))]
    [RequireComponent(typeof (CapsuleCollider))]
    public class RigidbodyFirstPersonController : MonoBehaviour
    {
        [Serializable]
        public class MovementSettings
        {
            public float ForwardSpeed = 8.0f;   // Speed when walking forward
            public float BackwardSpeed = 4.0f;  // Speed when walking backwards
            public float StrafeSpeed = 4.0f;    // Speed when walking sideways
            public float RunMultiplier = 2.0f;   // Speed when sprinting
           public KeyCode RunKey = KeyCode.LeftShift;
            public float JumpForce = 30f;
            public AnimationCurve SlopeCurveModifier = new AnimationCurve(new Keyframe(-90.0f, 1.0f), new Keyframe(0.0f, 1.0f), new Keyframe(90.0f, 0.0f));
            [HideInInspector] public float CurrentTargetSpeed = 8f;

#if !MOBILE_INPUT
            public bool m_Running;
#endif

            public void UpdateDesiredTargetSpeed(Vector2 input)
            {
               if (input == Vector2.zero) return;
                if (input.x > 0 || input.x < 0)
                {
                    //strafe
                    CurrentTargetSpeed = StrafeSpeed;
                }
                if (input.y < 0)
                {
                    //backwards
                    CurrentTargetSpeed = BackwardSpeed;
                }
                if (input.y > 0)
                {
                    //forwards
                    //handled last as if strafing and moving forward at the same time forwards speed should take precedence
                    CurrentTargetSpeed = ForwardSpeed;
                }
#if !MOBILE_INPUT
               if (Input.GetKey(RunKey))
               {
                   //LINE 49 starts here>>>>>>>>>>>>>>>>>>>>
var characterStaminaInstance = "GUISurvival.js";
                    characterStaminaInstance = GameObject.FindObjectOfType("GUISurvival").GetComponent("GUISurvival");
         

                    if (characterStaminaInstance.currentStamina <= 0) {
                        CurrentTargetSpeed = ForwardSpeed;
                        m_Running = false;
                    }
                    else
                    {
                   CurrentTargetSpeed *= RunMultiplier;
                   m_Running = true;
                    }
               }
               else
               {
                   m_Running = false;
               }
#endif
            }

#if !MOBILE_INPUT
            public bool Running
            {
                get { return m_Running; }
            }
#endif
        }


        [Serializable]
        public class AdvancedSettings
        {
            public float groundCheckDistance = 0.01f; // distance for checking if the controller is grounded ( 0.01f seems to work best for this )
            public float stickToGroundHelperDistance = 0.5f; // stops the character
            public float slowDownRate = 20f; // rate at which the controller comes to a stop when there is no input
            public bool airControl; // can the user control the direction that is being moved in the air
            [Tooltip("set it to 0.1 or more if you get stuck in wall")]
            public float shellOffset; //reduce the radius by that ratio to avoid getting stuck in wall (a value of 0.1f is nice)
        }


        public Camera cam;
        public MovementSettings movementSettings = new MovementSettings();
        public MouseLook mouseLook = new MouseLook();
        public AdvancedSettings advancedSettings = new AdvancedSettings();


        private Rigidbody m_RigidBody;
        private CapsuleCollider m_Capsule;
        private float m_YRotation;
        private Vector3 m_GroundContactNormal;
        private bool m_Jump, m_PreviouslyGrounded, m_Jumping, m_IsGrounded;


        public Vector3 Velocity
        {
            get { return m_RigidBody.velocity; }
        }

        public bool Grounded
        {
            get { return m_IsGrounded; }
        }

        public bool Jumping
        {
            get { return m_Jumping; }
        }

        public bool Running
        {
            get
            {
#if !MOBILE_INPUT
                return movementSettings.Running;
#else
               return false;
#endif
            }
        }


        private void Start()
        {
            m_RigidBody = GetComponent<Rigidbody>();
            m_Capsule = GetComponent<CapsuleCollider>();
            mouseLook.Init (transform, cam.transform);
        }


        private void Update()
        {
            RotateView();

            if (CrossPlatformInputManager.GetButtonDown("Jump") && !m_Jump)
            {
                m_Jump = true;
            }
        }


        private void FixedUpdate()
        {
            GroundCheck ();
            Vector2 input = GetInput();


                if ((Mathf.Abs (input.x) > float.Epsilon || Mathf.Abs (input.y) > float.Epsilon) && (advancedSettings.airControl || m_IsGrounded)) {
                    // always move along the camera forward as it is the direction that it being aimed at
                    Vector3 desiredMove = cam.transform.forward * input.y + cam.transform.right * input.x;
                    desiredMove = Vector3.ProjectOnPlane (desiredMove, m_GroundContactNormal).normalized;

                    desiredMove.x = desiredMove.x * movementSettings.CurrentTargetSpeed;
                    desiredMove.z = desiredMove.z * movementSettings.CurrentTargetSpeed;
                    desiredMove.y = desiredMove.y * movementSettings.CurrentTargetSpeed;
         
                    if (m_RigidBody.velocity.sqrMagnitude <
                      (movementSettings.CurrentTargetSpeed * movementSettings.CurrentTargetSpeed)) {
                        m_RigidBody.AddForce (desiredMove * SlopeMultiplier (), ForceMode.Impulse);
                    }

            }

            if (m_IsGrounded)
            {
                m_RigidBody.drag = 5f;

                if (m_Jump)
                {
                    m_RigidBody.drag = 0f;
                    m_RigidBody.velocity = new Vector3(m_RigidBody.velocity.x, 0f, m_RigidBody.velocity.z);
                    m_RigidBody.AddForce(new Vector3(0f, movementSettings.JumpForce, 0f), ForceMode.Impulse);
                    m_Jumping = true;
                }

                if (!m_Jumping && Mathf.Abs(input.x) < float.Epsilon && Mathf.Abs(input.y) < float.Epsilon && m_RigidBody.velocity.magnitude < 1f)
                {
                    m_RigidBody.Sleep();
                }
            }
            else
            {
                m_RigidBody.drag = 0f;
                if (m_PreviouslyGrounded && !m_Jumping)
                {
                    StickToGroundHelper();
                }
            }
            m_Jump = false;
        }


        private float SlopeMultiplier()
        {
            float angle = Vector3.Angle(m_GroundContactNormal, Vector3.up);
            return movementSettings.SlopeCurveModifier.Evaluate(angle);
        }


        private void StickToGroundHelper()
        {
            RaycastHit hitInfo;
            if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo,
                                   ((m_Capsule.height/2f) - m_Capsule.radius) +
                                   advancedSettings.stickToGroundHelperDistance, ~0, QueryTriggerInteraction.Ignore))
            {
                if (Mathf.Abs(Vector3.Angle(hitInfo.normal, Vector3.up)) < 85f)
                {
                    m_RigidBody.velocity = Vector3.ProjectOnPlane(m_RigidBody.velocity, hitInfo.normal);
                }
            }
        }


        private Vector2 GetInput()
        {
         
            Vector2 input = new Vector2
                {
                    x = CrossPlatformInputManager.GetAxis("Horizontal"),
                    y = CrossPlatformInputManager.GetAxis("Vertical")
                };
            movementSettings.UpdateDesiredTargetSpeed(input);
            return input;
        }


        private void RotateView()
        {
            //avoids the mouse looking if the game is effectively paused
            if (Mathf.Abs(Time.timeScale) < float.Epsilon) return;

            // get the rotation before it's changed
            float oldYRotation = transform.eulerAngles.y;

            mouseLook.LookRotation (transform, cam.transform);

            if (m_IsGrounded || advancedSettings.airControl)
            {
                // Rotate the rigidbody velocity to match the new direction that the character is looking
                Quaternion velRotation = Quaternion.AngleAxis(transform.eulerAngles.y - oldYRotation, Vector3.up);
                m_RigidBody.velocity = velRotation*m_RigidBody.velocity;
            }
        }

        /// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom
        private void GroundCheck()
        {
            m_PreviouslyGrounded = m_IsGrounded;
            RaycastHit hitInfo;
            if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo,
                                   ((m_Capsule.height/2f) - m_Capsule.radius) + advancedSettings.groundCheckDistance, ~0, QueryTriggerInteraction.Ignore))
            {
                m_IsGrounded = true;
                m_GroundContactNormal = hitInfo.normal;
            }
            else
            {
                m_IsGrounded = false;
                m_GroundContactNormal = Vector3.up;
            }
            if (!m_PreviouslyGrounded && m_IsGrounded && m_Jumping)
            {
                m_Jumping = false;
            }
        }
    }
}

GUISurvival.js Stamina Code starts on line 89

#pragma strict

var currentHealth : float = 100.0;
var maxHealth : float = 100.0;

var currentThirst : float = 100.0;
var maxThirst : int = 100;


var thirstMultiplyer : int = 50;

var currentHunger : float = 100.0;
var maxHunger : int = 100;
var hungerMultiplyer : int = 100;

public var currentStamina : float = 100.0;
var maxStamina : int = 100;
var staminaMultiplyer : int = 3;
public var CurrentTargetSpeed : float = 8f;
public var ForwardSpeed : float = 8.0f;
public var m_Running = false;
private var barLength = 0.0;
private var skillHeight = 0.0;
private var skillLength = 0.0;
private var skillxLoc = 0.0;
private var skillyLoc = 0.0;

private var RBController : CharacterController;
private var speed : float = 6.0f;
private var jumpSpeed : float = 8.0f;
private var gravity : float = 20.0f;
    private var moveDirection : Vector3 = Vector3.zero;


function Start()
{

RBController = GetComponent(CharacterController);

    barLength = Screen.width / 8;
    skillLength = Screen.width / 20;
    skillHeight = Screen.height / 8;
    skillyLoc = Screen.height - 100;
    skillxLoc = Screen.width / 4;
}

function Update()
{
    if(currentHealth <= 0)
    {
        CharacterDeath();
    }
 
    /* THIRST CONTROL SECTION*/
 
    //Normal thirst degredation
    if(currentThirst >= 0)
    {
        currentThirst -= Time.deltaTime / thirstMultiplyer;
    }
 
    if(currentThirst <= 0)
    {
        currentThirst = 0;
    }
 
    if(currentThirst >= maxThirst)
    {
        currentThirst = maxThirst;
    }
 
    /* HUNGER CONTROL SECTION*/
        if(currentHunger >= 0)
    {
        currentHunger -= Time.deltaTime / hungerMultiplyer;
    }
 
    if(currentHunger <= 0)
    {
        currentHunger = 0;
    }
 
    if(currentHunger >= maxHunger)
    {
        currentHunger = maxHunger;
    }
    /*STAMINA CONTROL*/
    if (Input.GetKey(KeyCode.LeftShift))
    {

 
   
                      if(currentStamina >= 0)    {
                    m_Running = true;
                  currentStamina -= Time.deltaTime / staminaMultiplyer * 8;
                  }
                  if(currentStamina <= 0)
                    {
                    currentStamina = 0;
                    }
                    if(currentStamina >= maxStamina)
                    {
                    currentStamina = maxStamina;
                    }
   
           
               if(currentStamina >= maxStamina)
    {
        currentStamina = maxStamina;
    } else {
    currentStamina += Time.deltaTime / staminaMultiplyer * 8;
       
        m_Running = false;

    }
              }

           

    /* DAMAGE CONTROL SECTION*/
    if(currentHunger <= 0 && (currentThirst <= 0))
    {
        currentHealth -= Time.deltaTime / thirstMultiplyer;
    }
 
    else
    {
        if(currentHunger <= 0 || currentThirst <= 0)
        {
            currentHealth -= Time.deltaTime / hungerMultiplyer;
        }
    }
}

function CharacterDeath()
{
    Application.LoadLevel("DeathMenu");
}

function OnGUI()
{
    //Icons
    GUI.Box(new Rect(5, 30, 60, 23), "Health");
    GUI.Box(new Rect(5, 55, 60, 23), "Thirst");
    GUI.Box(new Rect(5, 80, 60, 23), "Hunger");
    GUI.Box(new Rect(5, 105, 60, 23), "Stamina");
 
    //Health / Hunger / Thirst bars
    GUI.Box(new Rect(65, 30, barLength, 23), currentHealth.ToString("0") + "/" + maxHealth);
    GUI.Box(new Rect(65, 55, barLength, 23), currentThirst.ToString("0") + "/" + maxThirst);
    GUI.Box(new Rect(65, 80, barLength, 23), currentHunger.ToString("0") + "/" + maxHunger);
    GUI.Box(new Rect(65, 105, barLength, 23), currentStamina.ToString("0") + "/" + maxStamina);

    GUI.Box(new Rect(skillxLoc, skillyLoc, skillLength, skillHeight), "1");
 
}

you appear to be mixing your programming languages… putting unityscript into a c# script probably isn’t going to end well…

Are both these scripts on the same gameobject? if so you don’t need the “Find” at all, just use the GetComponent. Line 51 is totally redundant (and I think setting var to string type which you then try to load a component into… although I tend to avoid untyped variables so it might be retyping?).

If you don’t know the c# syntax for it try:

GUISurvival characterStaminaInstance = GetComponent<GUISurvival>();

oh and I’d also advise not having a single “huge” script to handle everything about the player… once you’re more comfortable with how scripts work together you really should break things down into more manageable single role scripts. And if you’re just starting out I really would suggest learning the new canvas based UI . It’s a lot more flexible and performs better.

As LeftyRighty said you shouldn’t mix script languages, but I’ve heard of pe
ople doing it

As far as part of your code:

var characterStaminaInstance = "GUISurvival.js";               
characterStaminaInstance = GameObject.FindObjectOfType("GUISurvival").GetComponent("GUISurvival");

var characterStaminaInstance should be of type GUISurvival class, but since they are cross language I’m not sure how or if this would even work,
With GameObject.findobjectoftype and getcomponent, I believe the “GUISurvival” in quotes should not be in quotes, because they are a Type of class you made and not a string

I also would suggest to not use the built in scripts, because it will generally only hurt you later.

It’s best to understand the GameObject basic components; Transform, Rigidbody, Colliders, and understand how to move, rotate, detect collision on your own without using premade scripts like CharacterControler and FPSController, plus you will have a lot more control over how they work if you make your own. I started off learning unity with CharacterController thinking it was a good thing but now I absolutely hate it.

I will give you an example of how to get a variable from another script using C#:

2 Classes, Player and Enemy
One Player object with the Player.cs script, called playerObj1
One Enemy object with the Enemy.cs script, called enemyObj1

Player.cs

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
    public int healthCurrent=5,healthMax=5;
    public Enemy someEnemy;

    void Start ()
    {
        someEnemy = GameObject.Find ("enemyObj1").GetComponent<Enemy> ();
        someEnemy.healthCurrent = 0;
    }
}

Enemy.cs

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour
{
    public int healthCurrent=5,healthMax=5;
    public Player thePlayer;

    void Start ()
    {
        thePlayer = GameObject.Find ("playerObj1").GetComponent<Player> ();
        thePlayer.healthCurrent = 0;
    }
}

If the scripts are contained in the same GameObject, (like a Player gameobject might contain the Player.cs script, a CameraControl.cs script and more), you can skip the GameObject.Find and just do (camControl = GetComponent())

The variables only need to be public if you are accessing them from another script.

Thank you everyone for the advise. I have found a c sharp script to handle the gui so i didnt have to attempt to rewrite it all with my limited knowledge. somebody converted the java script to c#. At this point the game loads and starts fine with no errors until try to move I get this.

I feel like im getting closer because the RigidBodyFirstPersonController auto completes and finds staminaBarDisplay. on line 53.

NullReferenceException: Object reference not set to an instance of an object
UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController+MovementSettings.UpdateDesiredTargetSpeed (Vector2 input) (at Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/RigidbodyFirstPersonController.cs:53)
UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController.GetInput () (at Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/RigidbodyFirstPersonController.cs:235)
UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController.FixedUpdate () (at Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/RigidbodyFirstPersonController.cs:157)

Here is the new GUI script that i am trying to use

using UnityEngine;
using System.Collections;



public class PlayerGUI : MonoBehaviour {
    public int currentHealth = 100;   // Current Health
    public int currentThirst = 100;   // Current Health
    public int currentHunger = 100;   // Current Health

    public Vector2 size = new Vector2 (120, 20);

    //health vars
    public Vector2 healthPos = new Vector2 (20, 20);
    public float healthBarDisplay = 1f;
    public Texture2D healthBarEmpty;
    public Texture2D healthBarFull;


    //hunger vars
    public Vector2 hungerPos = new Vector2 (20, 60);
    public float hungerBarDisplay = 1f;
    public Texture2D hungerBarEmpty;
    public Texture2D hungerBarFull;

    //thirst vars
    public Vector2 thirstPos = new Vector2 (20, 100);
    public float thirstBarDisplay = 1f;
    public Texture2D thirstBarEmpty;
    public Texture2D thirstBarFull; 

    //stamina vars
    public Vector2 staminaPos = new Vector2 (20, 140);
    public float staminaBarDisplay = 1f;
    public Texture2D staminaBarEmpty;
    public Texture2D staminaBarFull; 

    //stamina2 vars
    public Vector2 stamina2Pos = new Vector2 (20, 140);
    public float stamina2BarDisplay = 1f;
    public Texture2D stamina2BarEmpty;
    public Texture2D stamina2BarFull; 

    //fall rate
    public int healthFallRate = 150;
    public int hungerFallRate = 150;
    public int thirstFallRate = 100;
    public int staminaFallRate = 35;
    public int stamina2FallRate = 150;

    private UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController chMotor;
    private CharacterController controller;


    public bool canJump = false;
    public bool canRun = false;
    float jumpTimer = 0.7f;

    void Start(){
        chMotor = gameObject.GetComponent ("UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController") as UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController;

        controller = gameObject.GetComponent<CharacterController>();
    } 

    void OnGUI(){

        //health GUI
        GUI.BeginGroup (new Rect (healthPos.x, healthPos.y, size.x, size.y));
        GUI.Box (new Rect (0, 0, size.x, size.y), healthBarEmpty);

        GUI.BeginGroup (new Rect (0, 0, size.x * healthBarDisplay, size.y));
        GUI.Box(new Rect(0,0,size.x,size.y), healthBarFull);

        GUI.EndGroup ();
        GUI.EndGroup ();

        //hunger GUI
        GUI.BeginGroup (new Rect (hungerPos.x, hungerPos.y, size.x, size.y));
        GUI.Box (new Rect (0, 0, size.x, size.y), hungerBarEmpty);
       
        GUI.BeginGroup (new Rect (0, 0, size.x * hungerBarDisplay, size.y));
        GUI.Box(new Rect(0,0,size.x,size.y), hungerBarFull);
       
        GUI.EndGroup ();
        GUI.EndGroup ();

        //thirst GUI
        GUI.BeginGroup (new Rect (thirstPos.x, thirstPos.y, size.x, size.y));
        GUI.Box (new Rect (0, 0, size.x, size.y), thirstBarEmpty);
       
        GUI.BeginGroup (new Rect (0, 0, size.x * thirstBarDisplay, size.y));
        GUI.Box(new Rect(0,0,size.x,size.y), thirstBarFull);

        GUI.EndGroup ();
        GUI.EndGroup ();

        //stamina GUI
        GUI.BeginGroup (new Rect (staminaPos.x, staminaPos.y, size.x, size.y));
        GUI.Box (new Rect (0, 0, size.x, size.y), staminaBarEmpty);
       
        GUI.BeginGroup (new Rect (0, 0, size.x * staminaBarDisplay, size.y));
        GUI.Box(new Rect(0,0,size.x,size.y), staminaBarFull);
       
        GUI.EndGroup ();
        GUI.EndGroup ();

        //stamina2 GUI
        GUI.BeginGroup (new Rect (stamina2Pos.x, stamina2Pos.y, size.x, size.y));
        GUI.Box (new Rect (0, 0, size.x, size.y), stamina2BarEmpty);
       
        GUI.BeginGroup (new Rect (0, 0, size.x * stamina2BarDisplay, size.y));
        GUI.Box(new Rect(0,0,size.x,size.y), stamina2BarFull);
       
        GUI.EndGroup ();
        GUI.EndGroup ();

    }

    void Update(){

        //HEALTH CONTROL SECTION
        if(hungerBarDisplay <= 0 && (thirstBarDisplay <= 0))
        {
            healthBarDisplay -= Time.deltaTime / healthFallRate * 2;
        }
       
        else
        {
            if(hungerBarDisplay <= 0 || thirstBarDisplay <= 0)
            {
                healthBarDisplay -= Time.deltaTime / healthFallRate;
            }
        }
       
        if(healthBarDisplay <= 0)
        {
            //CharacterDeath();
        }
       
        //HUNGER CONTROL SECTION
        if(hungerBarDisplay >= 0)
        {
            hungerBarDisplay -= Time.deltaTime / hungerFallRate;
        }
       
        if(hungerBarDisplay <= 0)
        {
            hungerBarDisplay = 0;
        }
       
        if(hungerBarDisplay >= 1)
        {
            hungerBarDisplay = 1;
        }
       
        //THIRST CONTROL SECTION
        if(thirstBarDisplay >= 0)
        {
            thirstBarDisplay -= Time.deltaTime / thirstFallRate;
        }
       
        if(thirstBarDisplay <= 0)
        {
            thirstBarDisplay = 0;
        }
       
        if(thirstBarDisplay >= 1)
        {
            thirstBarDisplay = 1;
        }
       
        //STAMINA CONTROL SECTION
        if(staminaBarDisplay > 0 && Input.GetKey(KeyCode.LeftShift))
        {
            chMotor.movementSettings.m_RunSpeed = 10;
            //chMotor.movement.maxSidewaysSpeed = 10;
            staminaBarDisplay -= Time.deltaTime / staminaFallRate;
        }
       
        else
        {
            chMotor.movementSettings.m_RunSpeed = 6;
            //chMotor.movement.maxSidewaysSpeed = 6;w
            staminaBarDisplay += Time.deltaTime / staminaFallRate;
        }

        //STAMINA2 CONTROL SECTION
        if(stamina2BarDisplay >= 0)
        {
            stamina2BarDisplay -= Time.deltaTime / stamina2FallRate;
        }
        else
        {
           
            //chMotor.movement.maxSidewaysSpeed = 6;
            stamina2BarDisplay += Time.deltaTime / stamina2FallRate;
        }
       
        if(stamina2BarDisplay <= 0)
        {
            stamina2BarDisplay = 0;
        }
       
        if(stamina2BarDisplay >= 1)
        {
            stamina2BarDisplay = 1;
        }
       
        //JUMPING SECTION
        if(Input.GetKeyDown(KeyCode.Space) && canJump == true)
        {
            staminaBarDisplay -= 0.2f;
            Wait();
        }
       
        if(canJump == false)
        {
            //jumpTimer -= Time.deltaTime;
            chMotor.movementSettings.m_jump = false;
        }
       
        //if(jumpTimer <= 0)
        if(controller.isGrounded)
        {
            canJump = true;
            //chMotor.m_Jumping = true;
            //chMotor.m_Jump = true;
            //jumpTimer = 0.7f;
        }
       
        //COMMENTED THESE SECTIONS OUT - UPDATED 16/07/14
        //if(staminaBarDisplay <= 0.05)
        //{
        //canJump = false;
        //chMotor.jumping.enabled = false;
        //}
       
        //else
        //{
        //canJump = true;
        //chMotor.jumping.enabled = true;
        //}
       
        if(staminaBarDisplay >= 1)
        {
            staminaBarDisplay = 1;
        }

        if(staminaBarDisplay <= 0)
        {
            staminaBarDisplay = 0;
        }

        if(staminaBarDisplay <= 0.3f)
        {
            //ADDED line 181 here!
            //staminaBarDisplay = 0;
            chMotor.movementSettings.m_RunSpeed = chMotor.movementSettings.m_WalkSpeed;
            canJump = false;
            //chMotor.m_Jump = false;
            //chMotor.m_Jumping = false;
            //chMotor.m_Jumping = false;
            //chMotor.m_WalkSpeed = 6;
            //chMotor.movement.maxSidewaysSpeed = 6;
        }


    }


    void CharacterDeath()
    {
        if (healthBarDisplay <= 0f) {
            //Application.LoadLevel("scene");
        }

    }
   
    IEnumerator Wait()
    {
        yield return new WaitForSeconds(0.1f);
        canJump = false;
    }
   

}

HERE is the RigidBodyFirstPersonController c# script

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.Characters.FirstPerson
{
   
    [RequireComponent(typeof (Rigidbody))]
    [RequireComponent(typeof (CapsuleCollider))]
    public class RigidbodyFirstPersonController : MonoBehaviour
    {
        [Serializable]
        public class MovementSettings
        {
           
            public PlayerGUI PlayerHUDobj;

            public float m_RunSpeed = 16.0f;   // Speed when running forward
            public float m_WalkSpeed = 8.0f;   // Speed when running forward
            public float ForwardSpeed = 8.0f;   // Speed when walking forward
            public float BackwardSpeed = 4.0f;  // Speed when walking backwards
            public float StrafeSpeed = 4.0f;    // Speed when walking sideways
            public float RunMultiplier = 2.0f;   // Speed when sprinting
            public bool m_jump;
           public KeyCode RunKey = KeyCode.LeftShift;
            public float JumpForce = 30f;
            public AnimationCurve SlopeCurveModifier = new AnimationCurve(new Keyframe(-90.0f, 1.0f), new Keyframe(0.0f, 1.0f), new Keyframe(90.0f, 0.0f));
            [HideInInspector] public float CurrentTargetSpeed = 8f;

#if !MOBILE_INPUT
            public bool m_Running;
#endif

            public void UpdateDesiredTargetSpeed(Vector2 input)
            {
                         if (input == Vector2.zero) return;
                if (input.x > 0 || input.x < 0)
                {
                    //strafe
                    CurrentTargetSpeed = StrafeSpeed;
                }
                if (input.y < 0)
                {
                    //backwards
                    CurrentTargetSpeed = BackwardSpeed;
                }
                if (input.y > 0)
                {
                    //forwards
                    //handled last as if strafing and moving forward at the same time forwards speed should take precedence
                    CurrentTargetSpeed = ForwardSpeed;
                }
#if !MOBILE_INPUT
                PlayerHUDobj = GameObject.Find ("PlayerGUI").GetComponent<PlayerGUI> ();
                if (PlayerHUDobj.staminaBarDisplay > 0 && Input.GetKey(RunKey))
               {
                   
                   CurrentTargetSpeed *= RunMultiplier;
                   m_Running = true;

               }
               else
               {
                    CurrentTargetSpeed = m_WalkSpeed;
                   m_Running = false;
               }
#endif
            }

#if !MOBILE_INPUT
            public bool Running
            {
                get { return m_Running; }
            }
#endif
        }


        [Serializable]
        public class AdvancedSettings
        {
            public float groundCheckDistance = 0.01f; // distance for checking if the controller is grounded ( 0.01f seems to work best for this )
            public float stickToGroundHelperDistance = 0.5f; // stops the character
            public float slowDownRate = 20f; // rate at which the controller comes to a stop when there is no input
            public bool airControl; // can the user control the direction that is being moved in the air
            [Tooltip("set it to 0.1 or more if you get stuck in wall")]
            public float shellOffset; //reduce the radius by that ratio to avoid getting stuck in wall (a value of 0.1f is nice)
        }


   
        public Camera cam;
        public MovementSettings movementSettings = new MovementSettings();
        public MouseLook mouseLook = new MouseLook();
        public AdvancedSettings advancedSettings = new AdvancedSettings();


        private Rigidbody m_RigidBody;
        private CapsuleCollider m_Capsule;
        private float m_YRotation;
        private Vector3 m_GroundContactNormal;
        private bool m_Jump, m_PreviouslyGrounded, m_Jumping, m_IsGrounded;


        public Vector3 Velocity
        {
            get { return m_RigidBody.velocity; }
        }

        public bool Grounded
        {
            get { return m_IsGrounded; }
        }

        public bool Jumping
        {
            get { return m_Jumping; }
        }

        public bool Running
        {
            get
            {
 #if !MOBILE_INPUT
                return movementSettings.Running;
#else
               return false;
#endif
            }
        }


        private void Start()
        {
            m_RigidBody = GetComponent<Rigidbody>();
            m_Capsule = GetComponent<CapsuleCollider>();
            mouseLook.Init (transform, cam.transform);



        }


        private void Update()
        {
            RotateView();

            if (CrossPlatformInputManager.GetButtonDown("Jump") && !m_Jump)
            {
                m_Jump = true;
            }
        }


        private void FixedUpdate()
        {
            GroundCheck ();
            Vector2 input = GetInput();


                if ((Mathf.Abs (input.x) > float.Epsilon || Mathf.Abs (input.y) > float.Epsilon) && (advancedSettings.airControl || m_IsGrounded)) {
                    // always move along the camera forward as it is the direction that it being aimed at
                    Vector3 desiredMove = cam.transform.forward * input.y + cam.transform.right * input.x;
                    desiredMove = Vector3.ProjectOnPlane (desiredMove, m_GroundContactNormal).normalized;

                    desiredMove.x = desiredMove.x * movementSettings.CurrentTargetSpeed;
                    desiredMove.z = desiredMove.z * movementSettings.CurrentTargetSpeed;
                    desiredMove.y = desiredMove.y * movementSettings.CurrentTargetSpeed;
           
                    if (m_RigidBody.velocity.sqrMagnitude <
                      (movementSettings.CurrentTargetSpeed * movementSettings.CurrentTargetSpeed)) {
                        m_RigidBody.AddForce (desiredMove * SlopeMultiplier (), ForceMode.Impulse);
                    }

            }

            if (m_IsGrounded)
            {
                m_RigidBody.drag = 5f;

                if (m_Jump)
                {
                    m_RigidBody.drag = 0f;
                    m_RigidBody.velocity = new Vector3(m_RigidBody.velocity.x, 0f, m_RigidBody.velocity.z);
                    m_RigidBody.AddForce(new Vector3(0f, movementSettings.JumpForce, 0f), ForceMode.Impulse);
                    m_Jumping = true;
                }

                if (!m_Jumping && Mathf.Abs(input.x) < float.Epsilon && Mathf.Abs(input.y) < float.Epsilon && m_RigidBody.velocity.magnitude < 1f)
                {
                    m_RigidBody.Sleep();
                }
            }
            else
            {
                m_RigidBody.drag = 0f;
                if (m_PreviouslyGrounded && !m_Jumping)
                {
                    StickToGroundHelper();
                }
            }
            m_Jump = false;
        }


        private float SlopeMultiplier()
        {
            float angle = Vector3.Angle(m_GroundContactNormal, Vector3.up);
            return movementSettings.SlopeCurveModifier.Evaluate(angle);
        }


        private void StickToGroundHelper()
        {
            RaycastHit hitInfo;
            if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo,
                                   ((m_Capsule.height/2f) - m_Capsule.radius) +
                                   advancedSettings.stickToGroundHelperDistance, ~0, QueryTriggerInteraction.Ignore))
            {
                if (Mathf.Abs(Vector3.Angle(hitInfo.normal, Vector3.up)) < 85f)
                {
                    m_RigidBody.velocity = Vector3.ProjectOnPlane(m_RigidBody.velocity, hitInfo.normal);
                }
            }
        }


        private Vector2 GetInput()
        {
           
            Vector2 input = new Vector2
                {
                    x = CrossPlatformInputManager.GetAxis("Horizontal"),
                    y = CrossPlatformInputManager.GetAxis("Vertical")
                };
            movementSettings.UpdateDesiredTargetSpeed(input);
            return input;
        }


        private void RotateView()
        {
            //avoids the mouse looking if the game is effectively paused
            if (Mathf.Abs(Time.timeScale) < float.Epsilon) return;

            // get the rotation before it's changed
            float oldYRotation = transform.eulerAngles.y;

            mouseLook.LookRotation (transform, cam.transform);

            if (m_IsGrounded || advancedSettings.airControl)
            {
                // Rotate the rigidbody velocity to match the new direction that the character is looking
                Quaternion velRotation = Quaternion.AngleAxis(transform.eulerAngles.y - oldYRotation, Vector3.up);
                m_RigidBody.velocity = velRotation*m_RigidBody.velocity;
            }
        }

        /// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom
        private void GroundCheck()
        {
            m_PreviouslyGrounded = m_IsGrounded;
            RaycastHit hitInfo;
            if (Physics.SphereCast(transform.position, m_Capsule.radius * (1.0f - advancedSettings.shellOffset), Vector3.down, out hitInfo,
                                   ((m_Capsule.height/2f) - m_Capsule.radius) + advancedSettings.groundCheckDistance, ~0, QueryTriggerInteraction.Ignore))
            {
                m_IsGrounded = true;
                m_GroundContactNormal = hitInfo.normal;
            }
            else
            {
                m_IsGrounded = false;
                m_GroundContactNormal = Vector3.up;
            }
            if (!m_PreviouslyGrounded && m_IsGrounded && m_Jumping)
            {
                m_Jumping = false;
            }
        }
    }
}

I figured it out… nevermind. i was trying to find the script where i should have been looking for the game object that it is contained in…