Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Camando360 · Jan 19, 2012 at 12:02 AM · getcomponent

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. =)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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;
  }
 
 }
Comment
Add comment · Show 13 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Camando360 · Jan 19, 2012 at 06:05 PM 0
Share

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.

avatar image Kag359six · Jan 19, 2012 at 06:10 PM 0
Share

is the character motor attached to the same object as your move script?

avatar image Kag359six · Jan 19, 2012 at 06:13 PM 0
Share

i think I know, you might have to type "Character$$anonymous$$otor.movement.maxForwardSpeed = 123;"

avatar image Camando360 · Jan 19, 2012 at 06:39 PM 0
Share

Annnnndddd IT WOR$$anonymous$$S! Thanks!!

avatar image Kag359six · Jan 19, 2012 at 06:44 PM 1
Share

make sure you check this answer as the right one so people dont keep posting! and no problem!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges