- Home /
C# How to Access Character Controller's Properties without Declaring a Character Controller
Hi everyone, is it possible to access a character controller's properties such as isGrounded or Move without declaring one? I have a gameobject that has a character controller and I simply would like to reference that rather than having to assign it to a declared Character Controller within my script. I've tried gameobject.CharacterController.Move and gameobject.CharacterController.isGrounded but it neither of them worked.
Answer by jiteshvm · Apr 22, 2013 at 10:07 PM
You can access it by using :
gameObject.GetComponent<CharacterController>().isGrounded
I might add that if you do this frequently, it's much more efficient to cache the CharacterController in a field or property.
Your answer
Follow this Question
Related Questions
C# Need Help converting from Rigidbody to Character Controller 0 Answers
C# FP_Camera not following Character Controller 0 Answers
C# CharacterController.SimpleMove Goes on Forever 1 Answer
C# Character Controller Collision If Statement 2 Answers
Converting C# Controller from WASD Controls to Click-Based 1 Answer