- Home /
Sprint Script
So i'm working on a sprint script for my First Person Controller. The default one that comes with unity. What i have so far is this: function Update () { if(Input.GetKeyDown(KeyCode.F)) { GetComponent(CharacterMotor.maxForwardSpeed(123)); } }
I get the following error: maxForwardSpeed is not a member of character motor. I am VERY new to coding so please have mercy on my noobyness. =)
Answer by Hybris · Jan 19, 2012 at 04:14 PM
Unity thinks CharacterMoter is an component, and there is no variable maxForwardSpeed, what you could do is rename the Script. And if you want to acces the script make the maxForwardSpeed variable static by saying static var instead of just var, in the other script call the script name like this:
ExampleScript.maxForwardSpeed = 123;
Answer by Kag359six · Jan 19, 2012 at 05:18 PM
Click here for character controller fps script
If you want to make your own move script, check this out for a better understanding of character controllers WITHOUT the characterMotor script.
Answer by Kag359six · Jan 19, 2012 at 05:22 PM
as for your problem, I think that you need to do the following:
function Update() {
var motorScript = transform.GetComponent(CharacterMotor);
if(Input.GetKeyDown("f")) // key should be a string, not sure what you did
{
motorScript.maxForwardSpeed = 123;
}
}
Well that makes sense but i still get an error when i press the 'F' button: $$anonymous$$issingFieldException: Field 'Character$$anonymous$$otor.maxForwardSpeed' not found.
is the character motor attached to the same object as your move script?
i think I know, you might have to type "Character$$anonymous$$otor.movement.maxForwardSpeed = 123;"
make sure you check this answer as the right one so people dont keep posting! and no problem!
Your answer

Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
'thrust' is not a member of UnityEngine.Component 1 Answer
create GUI.Label and then access to it.. 2 Answers
Problems assigning transforms on another script during Start(). 2 Answers
How do I select a joint component from a GameObject that has multiple joint components? 1 Answer