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 ImDose · Feb 27, 2013 at 06:08 AM · hownumberlivestoof

How to make player lose lives?

I'm making a 2d platformer, and I want the player to lose lives when he dies. Here's what I've got so far:

 public var Lives = 3;
 
 
 public function OnGUI() {
     (GUI.Button (Rect ( 10, 50, 100, 30 ), "Lives: "  + Lives));
     }
 
 
 public function OnTriggerEnter (hit : Collider) : IEnumerator {
     if (hit.collider.tag == "DeathZone") {
     Application.LoadLevel(0);
     Lives = Lives - 1;
     }
 }


Also how would I print the number of lives onto the screen without using a GUI.Button? Sorry I'm pretty new to this. :)

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

3 Replies

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

Answer by appearance · Feb 27, 2013 at 06:45 AM

You are decreasing lives @line: 12, but before that "Application.LoadLevel(0)" will load the level again. Hence, your script which holds the Lives var will also get reset and your player never looses lives.

You have to separate the Lives data from this class or do not use Application.LoadLevel().

See how you can manage and come up with new code blocks if you still face the problem.

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 robertbu · Feb 27, 2013 at 06:58 AM

You can display the information using GUI.Label. @appearance is right about your data getting reset each time you do an Application.LoadLevel(). If you want to continue to use this method, take a look at Object.DontDestroyOnLoad().

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 kkyriakos · Oct 09, 2016 at 07:49 AM

There are lots of cheap plugins out there that will help integrate lives in your game very easily. I recommend "Life System Pro - Easy Lives Integration for Freemium Games" found here https://www.assetstore.unity3d.com/en/#!/content/69842

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 RoniBoss · Mar 10, 2020 at 10:47 AM 0
Share

ad and a scam

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

12 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

Related Questions

Textfield in javascript, make unity read it on pressing enter 1 Answer

How to check my Game System Requirements? 2 Answers

What are the prerequisites of using Unity? 1 Answer

How to update unity web player 0 Answers

How to pass variables in a Network using RPC function(s) 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