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 ma22be61 · Jun 17, 2015 at 07:48 PM · javascriptmovementbooleanreload

Slow down character while reloading.

Hello guys! I want to slow down my character while he's reloading. That's my movement script :

 var speed : float = 6.0;
     var jumpSpeed : float = 8.0;
     var gravity : float = 20.0;
 
     private var moveDirection : Vector3 = Vector3.zero;
 
     function Update() {
         var controller : CharacterController = GetComponent.<CharacterController>();
         if (controller.isGrounded) {
             // We are grounded, so recalculate
             // move direction directly from axes
             moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                     Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             
             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
             }
         }
 
         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;
         
         // Move the controller
         controller.Move(moveDirection * Time.deltaTime);
     }

That's the second script :

 function Update()
 {
 if(boolReload==true)
 GameObject.Find("SG_Player").GetComponent("weapon_preview").speed=2.0f;
 }

But I get the following error : "BCE0019: 'speed' is not a member of 'UnityEngine.Component'". How can I fix it?

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

2 Replies

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

Answer by SteveFSP · Jun 17, 2015 at 08:12 PM

Basically what is happening is that Unity can't tell what type GetComponent() is supposed to return, so it assumes the type is UnityEngine.Component. Take a look at the examples in GameObject.GetComponent.

Your best option is to use the 'type' overload, rather than the 'string' overload like you did in your example. That will tell Unity what type to expect. So if 'weapon_preview' is the name of the first script, then simply leave out the quotes. So something like this:

 GameObject.Find("SG_Player").GetComponent(weapon_preview).speed=2.0f;  # No quotes.

If you need to use a string overload for some reason, then take a look at the second example in the API documentation I linked to above. So you'll need to do something like this:

 var player : weapon_preview;  # This lets unity know how to 'cast' the variable.
 player = GameObject.Find("SG_Player").GetComponent("weapon_preview");
 player.speed=2.0f;

Comment
Add comment · Show 1 · 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 ma22be61 · Jun 17, 2015 at 08:34 PM 0
Share

Thank you ! :) Now all works perfectly !

avatar image
1

Answer by Tekksin · Jun 17, 2015 at 08:11 PM

just realized your first script said you had the speed variable. The comment below mine is correct. I didn't realize you had quotes around the name.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

auto run key 1 Answer

Slowing Down When Sliding Across Walls 2 Answers

Horizontal axis not working after animation 1 Answer

I am trying to make a movement script for my main camera but it isnt working! 2 Answers

I have a movement script, but how can i make it so i can move half the speed while in the air. 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