- Home /
Access Variable From FirstPersonController Script
I want to access the FirstPersonController script on my Player GameObject to access the m_IsWalking boolean to find out if the player is walking and play an animation if they are and Idle animation if they aren't
I've Tried: FirstPersonController script = GameObject.FindGameObjectWithTag("Player").GetComponent("FirstPersonController");
Bool isWalking = script.m_IsWalking;
AND I'VE TRIED
FirstPersonController script = GameObject.FindGameObjectWithTag("Player").GetComponent<FirsPersonController>;
Bool isWalking = script.m_IsWalking;
Could someone tell me how to access the m_IsWalking boolean from another script?
Answer by B3aT · Mar 16, 2015 at 03:55 PM
I do not have the source code of FirstPersonController, but if the variable is private or protected, you cannot access it directly. You need a getter, if it does not exists you can create it
public bool IsWalking(){
return m_IsWalking;
}
I recommend to look directly at the animation currently running (game object -> animation component -> animation controller ) http://docs.unity3d.com/ScriptReference/Animator.html , you need to see in which state is it now (or in a transition).
Another way is to see if it has velocity http://docs.unity3d.com/ScriptReference/Animator-velocity.html
I found a way to access it by adding this at the top of my script
using UnityStandardAssets.Characters;