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 NDJoshi · Mar 13, 2014 at 12:51 PM · timehealth

Reduce health constant

Hey, I am making a game in which the health of the character reduces constantly whether it is hit by any obstacle or not. But, if the character is hit by any obstacle, then the health will reduce by some particular amount. The deduction of health will be dependent on the time. I am using C#. if any one can help me with this, it would be a great help. Thanx in advance.

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 wildex999 · Mar 13, 2014 at 01:06 PM 0
Share

I think you need to explain a bit more what you need. What do you mean by "deduction of health will be dependent on the time"?

avatar image NDJoshi · Mar 13, 2014 at 03:21 PM 0
Share

Hey @wildex999 Thanx for taking interest. "deduction of health will be dependent on the time" means every frame or every time frame the health will be reduced by some perticular amount.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ChrisJoosten · Mar 13, 2014 at 01:39 PM

Do you mean something like this?

  float Health = 100f;
 
 
     void Update(){
     Health -= 1f * time.Deltatime;
     }
     
     void OnCollisionEnter(Collision coll){
     if(coll.gameobject.tag == "GameObject You Want"){
     Health - 20f;
     }
  }
 
Comment
Add comment · Show 5 · 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 NDJoshi · Mar 13, 2014 at 03:15 PM 0
Share

Yes @ChrisJoosten, Its exactly i want, By i am not sure if ""Health -= 1f * time.Deltatime;"" will work or not. And the object which will decide how much health to reduce per time frame has to be dynamic. Thanx in advance.

avatar image ChrisJoosten · Mar 13, 2014 at 03:23 PM 0
Share

By dynamic do you mean different damage for every object that it's colliding with?

Or do you mean it has to be a different amount of damage for every collision?

avatar image NDJoshi · Mar 14, 2014 at 05:21 AM 0
Share

No, Dynamic in the sense, it should not be any particular value set in the script. But, it has to be the variable that can be change the value at run time.

avatar image getyour411 · Mar 14, 2014 at 06:22 AM 0
Share

Change "1f" to "myVar" and decide for yourself how and when to change it.

avatar image ChrisJoosten · Mar 14, 2014 at 12:07 PM 0
Share

something like..

 float $$anonymous$$Damage = 1f;
 float maxDamage = 50000f; //For Example
 
 float damageDealth;
 
 void Update(){
  damageDealth = Random.Range($$anonymous$$Damage, maxDamage);
 
 }

It picks something between them.

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to lose a specific amount of health over time 2 Answers

How would I decrease a variable over time based on distance? 1 Answer

Decrease Health every 5 mins or Time script? 2 Answers

Update not being called every frame 2 Answers

[SOLVED] Need Help "For" loop to execute in specific Intervals 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