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 aidenkael · Nov 01, 2013 at 07:10 PM · c#transformtranslate

Object doesn't move if variable is used?

If I have this code:

 if (bally>posy)
         {
             //above
             transform.Translate(0,speed*Time.deltaTime,0);
             print ("I should be moving up");
         }
         if (bally<posy)
         {
             transform.Translate(0,-speed*Time.deltaTime,0);
             print ("I should be moving down");
         }

Nothing happens, but if I have 1f, and -1f instead of "speed", then it works as it should. Anyone know why?

Comment
Add comment · Show 2
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 01, 2013 at 07:11 PM 0
Share

$$anonymous$$y guess 'speed' is not a private variable. If it is not a private variable then its initial value will be taken from the inspector rather than how you've initialized it at the top of the file.

avatar image aidenkael · Nov 01, 2013 at 07:13 PM 0
Share

speed is a public variable and the inspector has it at 1f as well

1 Reply

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

Answer by Huacanacha · Nov 01, 2013 at 07:15 PM

Add a Debug.Log to see what your speed value is. I'd say it is probably zero which will cause the translation to have no effect, or a very small number so the movement is barely noticeable.

Comment
Add comment · Show 3 · 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 aidenkael · Nov 01, 2013 at 07:16 PM 0
Share

It was at 0, however it is set here public float speed = 1f; and also at 1 in the inspector....

avatar image aidenkael · Nov 01, 2013 at 07:17 PM 0
Share

I changed it from public to private and it worked. Interesting....

avatar image Huacanacha · Nov 01, 2013 at 07:29 PM 0
Share

If you change the default value of a public variable in a script after assigning that script to an object, I think the new default value isn't taken into account. $$anonymous$$aybe something like that happened. If you change the variable back to public now it will probably work... you could also just remove and add the script again if this happens in the future.

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

15 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

Related Questions

Simple C# Vector2D Moving Question 1 Answer

How can I move an object a certain distance, once? 2 Answers

Multiple Cars not working 1 Answer

Move GameObject along a line according to the players look direction 3 Answers

Quick question on transform.Translate(); C# 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