Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Scripting' started by B-30, Jul 13, 2015.

  1. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    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:
    Code (csharp):
    1. player = GameObject.Find ("RigidBodyFPSController");
    followed by

    Code (csharp):
    1. RigidbodyFirstPersonControllerFPSscript;
    2. FPSscript = player.GetComponent ("RigidbodyFPSController") asRigidbodyFirstPersonController;
    3. 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
    Code (csharp):
    1. UnityStandardAssets.Characters.FirstPerson FPSscript;
    2. FPSscript = player.GetComponent ("RigidbodyFPSController") as FirstPerson;
    3. FPSscript.m_Jump ("true");
    But that says it's a namespace not a type.

    B
     
    Last edited: Jul 13, 2015
  2. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    One way would be by finding the gameObject that has the "RigidbodyFirstPersonController" and then send a message :
    Code (CSharp):
    1. //include the namespace
    2. using UnityStandardAssets.Characters.FirstPerson;
    3.  
    4. private RigidbodyFirstPersonController fpController;
    5.  
    6. void Start(){
    7.  
    8. //find the FirstPersonController
    9. fpController = GameObject.FindObjectOfType(typeof(RigidbodyFirstPersonController)) as RigidbodyFirstPersonController;
    10.  
    11. //Send your message
    12. fpController.SendMessage("YourFunction");
    13. }
     
    B-30 likes this.
  3. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    Thanks so much @Intense_Gamer94, I wasn't including the namespace. You solved it for me, thank you very much!
    B

     
  4. B-30

    B-30

    Joined:
    Nov 3, 2014
    Posts:
    28
    Ps, How do I mark the post "Solved"?

     
  5. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Glad I could help :)

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