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 EpicOverkill982 · Oct 16, 2011 at 06:34 AM · regenerationhealth

regenerating health script

hi. would anyone know where i could find a regenerating health script. because i really need one for my game. and if there is one where could i find one that shows a 'hit' screen until your health is back up? thanks in advance

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 Proportion · Oct 16, 2011 at 06:48 AM 0
Share

soz i dont think this is the place to ask for scripts. its more the place to ask questions about scripts your making. that way you will get heaps better at your game making. if you give it a go i would start reading this http://unity3d.com/support/documentation/ScriptReference/Time-fixedTime.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · Oct 16, 2011 at 07:08 AM

I don't usually like writing people's code for them, but I don't have anything to do for the next 5 minutes, so here we go...

public float maxHealth = 100; public float regeneration = 5; float health = 100; // Decrease this in your 'damage' script- I won't go into that here

void Start() { health = maxHealth; }

void Update() { if(health < maxHealth) { health += regeneration * Time.deltaTime; if(health > maxHealth) { health = maxHealth; } } }

void OnGUI() { if(health < maxHealth) { Color tempColour = GUI.color; GUI.color = Color.red; GUI.Label(new Rect((Screen.width / 2) - 70, (Screen.height / 2) - 20, 140, 40), "OH NOE THE PAIN"); GUI.color = tempColour; } }

There you go! I can make a variant which fades the message out depending on how much health you have, but that's a different matter. You may want to define a custom GUIStyle which has bigger writing, and use that instead, but that's not entirely a scripting matter, so I can't really put it here.

EDIT: That bit about not liking to write people's code was a lie.

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 EpicOverkill982 · Oct 16, 2011 at 08:51 AM 0
Share

Thank you for the sript

avatar image EpicOverkill982 · Oct 16, 2011 at 09:00 AM 0
Share

when i try to put it in it has over ten compiler issues.

avatar image Ludiares.du · Oct 16, 2011 at 09:38 AM 1
Share

It's in C#, not javascript

avatar image syclamoth · Oct 16, 2011 at 11:10 AM 1
Share

And you don't just copypasta the entire script- it's supposed to go inside a class!

avatar image Phoskryfes · Oct 30, 2012 at 11:56 AM 0
Share

they got a point though. I think you should read this. It's about asking questions here.

http://answers.unity3d.com/questions/133869/how-to-ask-a-good-question.html

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

Health Regeneration speeds up when action performed? 1 Answer

Regain health on GUI 2 Answers

C# Health regeneration delay after hit 0 Answers

How can i make my health regenerate? 1 Answer

Help With Health Regeneration 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