Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by nirto_pineapplez · Jun 26, 2016 at 02:15 PM · javascriptscript.damagenumbershealth

How to change numbers in unity

hey i have a basic health script (e.g picturealt text) witch destroys the player when reached 0 so i was wondering if you could figure out how to when the bullet collides with player take away 30 point of the script......... i would be very grateful if you help

here is the health script:

 var curHealth : int = 100; var maxHealth : int = 100;
 
 function Start () { }
 
  function Update()
  {
      // if the player is dead destroy him
      if(curHealth <= 0)
          Destroy(gameObject);
      // if curHelath < 0 -> curHealth = 0; if curHealth > 100 -> curHealth = 100
      curHealth = Mathf.Clamp(curHealth,0,100);
  }

hope this helps thanks

.harry

screen-shot-2016-06-26-at-103527-pm.png (9.8 kB)
Comment
Add comment · Show 1
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 phxvyper · Jun 26, 2016 at 03:15 PM 0
Share

Hey harry. When you post a question that has code, please highlight your pasted code and then click the "101/010" button in the formatting toolbox above the text editor. You'll notice I've already done this for you, and your question looks a lot more roomy and readable because of it!

Please do this in the future, and you'll get upvoted and answered more often :)

1 Reply

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

Answer by phxvyper · Jun 26, 2016 at 03:18 PM

You can subtract values from properties and variables using basic maths arithmetic:

 curHealth = curHealth - 30;

As an example of implementation, you could do this on key press:

 function Update() {
     ...
     if (Input.GetKeyDown(KeyCode.G)) {
         curHealth -= 30;
     }
     ...
 }

Whenever you press G on your keyboard, curHealth should decrease by 30!

Comment
Add comment · Show 1 · 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 nirto_pineapplez · Jun 27, 2016 at 06:00 AM 0
Share

thank you so much you have helped me a lot thank you!!!!!! (ノ◕ヮ◕)ノ*:・゚✧

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Health Script 2 Answers

Interesting Script Problem 1 Answer

Unity: Player take damage from enemy projectile 2 Answers

How do I do a Immunity time after being hited? 2 Answers

Health pickup script issue -1 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