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 oliver-jones · Nov 18, 2010 at 03:14 AM · mathpercentagepercent

Simple Maths Problem (I Suck At Maths)

Okay,

I have a variable called EnemyRemaining, which equals 30 to begin with, but an enemy is destroyed every 5 seconds (this bit isn't relevant)

So, my variable is decreasing from 30, to 29, to 28 ....

But I would like to display this as an overall percentage. When I have 30 Enemies Remaining - the overall percentage is 0% complete, then when all the enemies die off to 0 Enemies Remaining, the overall percentage is 100% complete (15 enemies = 50% ...)

Could someone help me with the equation and script.

Thanks

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
0
Best Answer

Answer by oliver-jones · Nov 18, 2010 at 03:56 AM

Solved it my self:

static var EnemyRemaining : float = 30; // Decreased every time enemy is killed static var EnemyMax : float = 30; // Total amount of enemy to begin with static var EnemyAdding : float = 0; //IMPORTANT BIT - Increases every time enemy is killed - from 0 to 30 -- this allows my percentage to read the other way round - from 100% -0% to 0% - 100%

var FindOne : float; // This gets EnemyAdding(remaining) and divides it by EnemyMax(total); static var FindTotal : int; // This then multiplies it my 100 to make it a %.

function Update() { FindOne = EnemyAdding / EnemyMax; FindTotal = FindOne * 100; print(FindTotal); }

If you want the percentage to read the opposite way round, then I replace EnemyAdding with EnemyRemaining.

The Destroy Enemy has:

EnemyRemaining --;
EnemyAdding ++;
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
avatar image
0

Answer by denewbie · Nov 18, 2010 at 03:58 AM

I've answered something similar to this before here

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

No one has followed this question yet.

Related Questions

Calculating percentage in code is reversed? 1 Answer

Progression height affected by the width ? why 1 Answer

How can I dynamically change the percentage value so that it always adds up to 100%? 1 Answer

How to move slider same amount with different max values when moving it by a percentage Unity 1 Answer

Math - distance to percentage 2 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