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 AndreasX12 · Nov 09, 2012 at 06:53 PM · charactercontrollerspeedchangeonclick

Click on an object and then edit the speed of my player?

Hello, I'am new to all the scripting languages that unity uses, so I would ask if someone maybe knew how to make a script that will do the following:

When I click on an in-game object (such as a box) (A hotkey would also work), it should change the speed of the player to something like 12 (I'am using the standard 'Character Controller').

The "property" to change the speed is: First Person Controller>Character Motor (Script)>Movement>Max Forward Speed

Thanks, Andreas :)

I know other scripting languages, so I'am able to understand most scripts :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer Wiki

Answer by IgnoranceIsBliss · Nov 09, 2012 at 09:59 PM

The hard part is actually detecting the click. This is a C# example for a hotkey...

 void Update()
 {
    //Step One - Detect The Key Being Pressed...
    if (Input.GetKeyDown(KeyCode.Space))
    {
        //Now, get the 'Character Motor' component from our object (I'm assuming that this script is on the object you want to control)

        CharacterMotor Mtr = GetComponent<CharacterMotor>();

        //And change the maximum forward speed
        Mtr.movement.maxForwardSpeed = 12;
    }
 }    


The intellisense will really help you here - once you have your CharacterMotor object, just type 'Mtr' followed by a period (.) and all of the options and members of this particular object will appear.

If you are going to script in Unity, make sure you are quite comfortable with one of the main languages (my personal preference is C#).

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 AndreasX12 · Nov 10, 2012 at 08:26 AM 0
Share

Thanks, I'am sure that this is just what I'am looking for, but when I click "Play" in Unity3D it says:

error CS0246: The type or namespace name `Character$$anonymous$$otor' could not be found. Are you missing a using directive or an assembly reference?

avatar image AndreasX12 · Nov 10, 2012 at 11:45 AM 0
Share

I placed the script in thee "root" folder, and now it works :), Thank you so much for the script :)

avatar image Kmulla · Nov 10, 2012 at 04:56 PM 0
Share

If he provided the solution, you can accept the answer by clicking the gray tick to the left of the answer. That way helpful people, looking through answers, can see that you already have a solution AND if somebody in the future, with the same question, knows that this one helped you to at solution :)

avatar image AndreasX12 · Nov 10, 2012 at 05:23 PM 0
Share

Thanks, I'm still new to the forums, I'll do that from now :)

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

11 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

Related Questions

Check CharacterController's Velocity 0 Answers

interpolate a move variable 0 Answers

Rotate Character Controller 1 Answer

Character movement relative to both camera and transform 2 Answers

Rotate character controller on all axis 0 Answers


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