accessing charactercontroller

I want to check if my character is jumping and then check if it is falling to play a jump an fall animation. I have a script that I am using as reference that accesses the CharacterController to check the velocity in the y direction for this. My problem is that it is returning a null for the velocity. The script is attached to my mesh which has the animations attached to it. The mesh is a child of the CharacterController. How do I access the CharacterController in the script? I am using GetComponent(CharacterController)

Thanks for any help.


You should have a CharacterController member in the script you’re going to use it.
Then, you should call GetComponent(CharacterController) in the Start() or Awake() function,
so you only have to call this once.

The object you’re calling the GetComponent on must be the gameobject with the CharacterController component attached.

If you have to call it a parent object, you could use GetComponentInChildren, which takes the first component in its children which matches the type of component you’re looking for.

Hope that helps.