[SOLVED] How to GetComponent or send a message to Unity's RigidbodyFirstPersonController?

I can’t work out how to get component or send a message from a game object to Unity’s standard Rigidbody First Person Controller using GetComponent. Could somebody kindly tell me the syntax?

So far I have tried:
player = GameObject.Find ("RigidBodyFPSController");followed by

RigidbodyFirstPersonControllerFPSscript;
FPSscript = player.GetComponent ("RigidbodyFPSController") asRigidbodyFirstPersonController;
FPSscript.m_Jump ("true");

But that says it can’t find the type or namespace, am I missing a using directive or an assembly reference, and

UnityStandardAssets.Characters.FirstPerson FPSscript;
FPSscript = player.GetComponent ("RigidbodyFPSController") as FirstPerson;
FPSscript.m_Jump ("true");

But that says it’s a namespace not a type.

B

One way would be by finding the gameObject that has the “RigidbodyFirstPersonController” and then send a message :

//include the namespace
using UnityStandardAssets.Characters.FirstPerson;

private RigidbodyFirstPersonController fpController;

void Start(){

//find the FirstPersonController
fpController = GameObject.FindObjectOfType(typeof(RigidbodyFirstPersonController)) as RigidbodyFirstPersonController;

//Send your message
fpController.SendMessage("YourFunction");
}
1 Like

Thanks so much @Ian094 , I wasn’t including the namespace. You solved it for me, thank you very much!
B

Ps, How do I mark the post “Solved”?

Glad I could help :slight_smile:

Just go to “Thread Tools” above your first post and edit the title.