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 Foxosaur · Jun 09, 2012 at 07:50 PM · counterpowerup

Totalling powerup values

I'm counting how many powerups a given player collects in a game via a static variable that increments per powerup.

What would be the best way to take a value from each powerup that was collected and gain a total to then adjust some player based stats? If it helps the object is destroyed once collected.

I have three ideas currently and would imagine the first one to be better?

1) I do something similar to foreach(powerup) {stat+40;}
2) I just multiply the number of powerups by a set ammount and add that value onto the stat affected - possible in update()?
3) Add the stat immediately on interaction of the object itself (at the time of the object being destroyed - in the powerup script itself)

Thank you in anticipation.

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 hijinxbassist · Jun 09, 2012 at 08:52 PM 0
Share

I always use the third, that way a single type of power up can have separate values for each instance. if its always a set number you could multiply the total count, that would need to be stored just like the actual value would...so id probly just use the 3rd solution.

avatar image SamAgten · Jun 10, 2012 at 01:09 PM 0
Share

The question you need to ask yourself is: "how adaptable do I want this system to be". If your powerups add a static amount each time you can just go with the third option and increase the player stat. if however you'd like a varaible amount to be added by each powerup or add different kinds of powerups you're better of with a more robust and generic system. This also applies if the power-up only last for a short amount of time. You can do this by writing a class for your stats: This class would have a base amount and perhaps a list of increments with a timer attached to each one. You can then just ask this class for the current value of a stat. Your powerups would then add an increment to a certain stat using the interface provided by the class. It's the stats own responsibility to keep track of the TTL (time-to-live) of each powerup it receives. This ensures a high degree of cohesion in your code base.

Hope that makes sense :)

avatar image syclamoth · Jun 10, 2012 at 01:23 PM 0
Share

In general, you shouldn't be using static variables for this (or for ANYTHING). Specifically, the player should keep track of the powerups they have collected, and deter$$anonymous$$e their total stats based on the total strength of all the powerups they own. This way, individual powerups can be added and removed easily, without having to remember specifics about each powerup.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resouce script help 3 Answers

GuiText Score On Mouse Click 1 Answer

FPS + Time.time not accurate on iPhone5 1 Answer

Count Variable Acting Strange 1 Answer

Counting colors and keeping it in memory (javascript) 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