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 applejuices · Nov 25, 2013 at 10:37 PM · c#movementgetcomponentcharactermotor

Using C# and getcomponent...

I have a First Person Controller from the Unity Assets I imported. I'd like to know in C#, how to access the CharacterMotor Component's 'Max Forward Speed' variable from another script, as well as change it...

Comment
Add comment · Show 3
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 robertbu · Nov 25, 2013 at 10:46 PM 0
Share

$$anonymous$$ore information needed. What scrip defines 'Forwardmax', and what game object is it attached to?

avatar image applejuices · Nov 25, 2013 at 10:59 PM 0
Share

Forward max speed is A movement thingy (Its max forward speed.)made by the first person controller script. Its in the first person controller. I would just like to see a script that finds this, can maybe alter it too.

avatar image tanoshimi · Nov 25, 2013 at 11:04 PM 0
Share

Did you read the comments to your other question on the same subject...?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by clunk47 · Nov 26, 2013 at 12:02 AM

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour
 {
     //Create a motor variable.
     CharacterMotor motor;
 
     //Create your own speed variable.
     float mfs;
 
     //For testing purposes
     string label;
     
     void Start ()
     {
         //Be sure component is found before assigning.
         if(GetComponent<CharacterMotor>())
             motor = GetComponent<CharacterMotor>();
 
         //Check if motor is null or not before matching your speed with motor's speed. 
         //If you want to create your own speed on startup, just assign a float or int to mfs and remove this.
         if(motor != null)
             mfs = motor.movement.maxForwardSpeed;
     }
     
     void Update()
     {
         //Press and hold up or down on vertical axis to increase and decrease speed.
         //For Testing Purposes.
         mfs += (int)Input.GetAxis ("Vertical");
 
         //Be sure motor is not null before matching motor's speed with your variable's speed.
         if(motor)
             motor.movement.maxForwardSpeed = mfs;
 
         //Update label at runtime to output GUI.
         //For Testing Purposes.
         label = "Motor Script Max Forward Speed = " + motor.movement.maxForwardSpeed + "\n" + "Your Max Forward Speed = " + mfs;
     }
     
     void OnGUI ()
     {
         //Print label variable.
         GUILayout.Label (label);
 
         //Instructions.
         GUILayout.Label("\n" + "Press Up and Down Arrow keys (or W and S) to increase or decrease Max Forward Speed.");
     }
 }
Comment
Add comment · Show 4 · 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 applejuices · Nov 26, 2013 at 12:35 AM 0
Share

I better try my luck with JavaScript.

avatar image clunk47 · Nov 26, 2013 at 12:51 AM 1
Share

Dude. This is an example for you to copy and paste lol. If you want to simply access it without all the extra:

 float maxSpeed;
 
 void Start()
 {
     maxSpeed = GetComponent<Character$$anonymous$$otor>().movement.maxForwardSpeed;
 }

Really simple.

avatar image applejuices · Nov 26, 2013 at 01:34 AM 0
Share

If its soooo simple, why does it error out, half the crap is red.

avatar image clunk47 · Nov 26, 2013 at 01:43 AM 1
Share

Because you're not doing something right. The C-SHARP Example I posted above in my original answer has no errors. Attach it to your First Person Controller. First Person Controller should have Character $$anonymous$$otor attached. Be sure you're creating a C# script, not a Javascript and pasting this into it. Be sure you name your C# script Example in this case, since my class name is 'Example'. It IS really simple. You just need to be willing to learn, and when you have an issue, give details. "Half the crap" doesn't tell me a damn thing. I'm willing to help if you're willing to put some effort forth in asking a question.

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Bullet not moving from script 3 Answers

Camera will not move between given points 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