- Home /
Access Unity 5 standard assets scripts(javascript).
Hi, I have been brain storming all day on how to access the FirstPersonController script from the unity fps controller. Due to me being a such a noob can anyone tell me how to access it from a javascript and if possible disable it. I searched google for hours and didnt find any answers.
I would like to define a variable of it like so:
private var fpsController : FirstPersonController; //fpscontroller script!
I would like to to create an if statement like this:
if (Input.GetKeyDown(KeyCode.Tab))
{
_fpsController.enabled = false; //disables the fps controller script
camera.SetActive (false); // disables the camera
thanks for everyone willing to take there time to answer!
Answer by erebel55 · Jun 03, 2015 at 09:21 PM
Learn about GetComponent https://unity3d.com/learn/tutorials/modules/beginner/scripting/getcomponent http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html
You can use this to get a component that is attached to a GameObject.
So you attach the FirstPersonController to your player (or camera or w/e) and then you use GetComponent to get a reference to it. You can then do whatever you want with it.
Sometimes i wonder if i have a humans brain lol. Thanks for helping though now i can get on with my project!
Your answer

Follow this Question
Related Questions
Smoother dash with a Character Controller 2 Answers
RigidBody Character Controller Sinking into Floor? 1 Answer
Character Controller with Relative Gravity? 1 Answer
getting out of a vehicle 2 Answers
Character Controller Child Collisions 2 Answers