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
-3
Question by CowNecromancer · Apr 15, 2015 at 09:48 AM · javascripterror

Help with the code

alt text

why does plusDamage become 1 in the console when it is meant to be 1.1.

basically what i am trying to do is make it so what ever number you put in extra damage will be a percentage (e.g 10 will add 10% more damage to the damage outcome) by adding 100 then dividing by 100. put it in a calculator it says 1.1 which is the outcome i want, because down the bottom I times the outcome, but in unity it says 1.

my-code.png (17.5 kB)
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 fffMalzbier · Apr 15, 2015 at 09:46 AM 0
Share

Basic rules of calculation do apply to in JS / unity.

10 + 100 / 100 =11

(10+100) / 100 =1.1

avatar image CowNecromancer · Apr 17, 2015 at 12:23 AM 0
Share

Sorry I did not think it followed "Order of Operations" anyways in unity it is saying that 10 + 100 / 100 = 1? anyways I figured it out

avatar image LeonardNS · Apr 17, 2015 at 01:36 PM 0
Share

Looks like this problem is solved. Please mark a answer as the right one or make a new one yourself which says how you solved it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by YoungDeveloper · Apr 15, 2015 at 09:52 AM

It goes from right to left, it will divide 100 by 100 and only then add extraDamage - add brackets the prioritize.

 var plusDamage:float = (extraDamage + 100f)/100f;

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 CowNecromancer · Apr 15, 2015 at 11:49 PM 0
Share

dont worry, i got it to work in the function Start() the part where i did the maths there was alright, but for some reason it thought extradamage was 0, I know right once I figure that out It took me ages to figure it out. Until i stated the var in the function start. so 0 + 100 / 100 = 1, stupid glitches

avatar image YoungDeveloper · Apr 16, 2015 at 09:35 AM 0
Share

it was 0 because it was public and most likely was 0 in inspector, there are no "glitches", only incompetence.

avatar image CowNecromancer · Apr 17, 2015 at 12:24 AM 0
Share

why would it be 0 in inspector, I never touched inspector. So if I were to state it was 10 then in the inspector It should be defaultly 10. or is it always 0 to make life harder. I can see why your answer is probably correct, because when I stated the variable in Start() it worked probably because it was changing it in the inspector when i started it

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is not a Member of Collisions 2 Answers

Semi colon placement? unity error message 2 Answers

My Javascript is not opening 0 Answers

The name 'Message' does not denote a valid type ('not found'). 1 Answer

When I kill one enemy, the rest disapear, but still shoot 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