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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by rOBY GAMES · Sep 28, 2012 at 08:59 AM · playerlife

How to increase the life of the player?

Hi all! I plugged in my palyer life. every time I hit me a lever life. I want my player is now being increased life by taking a cube and doing so increases my life.

I am using this script to the player.

health control:

var health1 : Texture2D;

var health2 : Texture2D;

var health3 : Texture2D;

var health4 : Texture2D;

static var LIVES = 5;

function Update ()

{

switch(LIVES)

{

    case 4:
         guiTexture.texture = health4;
    break;

case 3: guiTexture.texture = health3;

break;

case 2: guiTexture.texture = health2;

break;

case 1: guiTexture.texture = health1;

break;

case 0:

Application.LoadLevel(0);

    break;
    
    

}

}

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 Fattie · Sep 28, 2012 at 09:01 AM 0
Share

use the "code" button (0101010) to format code. click EDIT and you get to make it tidy !!

avatar image Dreamblur · Sep 28, 2012 at 10:46 AM 0
Share

Are you asking about collision or how to edit the '-' character into a '+' character? =/

(And I'm not even going to say anything about how an array would optimize your code by a lot.)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by andytouch · Sep 28, 2012 at 01:55 PM

Firstly, use an Array to tidy up your lives GUI. It will keep your code clean and much more manageable and efficient.

Secondly, you would want to setup a collision on the player that when they collided with the cube, it will run this:

 lives +=1;
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 Cyber-X-Zone · Sep 28, 2012 at 01:50 PM

Add such a script to the trigger or the cube which increases a life that the script in the cube connects to the life script in player and increase it.... For Example:: The script for the cube can be like this:

 var lifeAmount = 1;//life to be added to the player
     //Change the playerLife to the name of script attached to the //player
     function ApplyPickup (playerLifeScript : playerLife)
 {
 
 switch (lifeAmount)
 {
 case 0:
    playerLifeScript.AddHealth(lifeAmount);
    break;
 
 function OnTriggerEnter(col : collider) {
 var playerLifeScript : playerLife = col.GetComponent(playerLife);
 }

And for the player, the script can be named as playerLife... var health : int = 6; var maxHealth : int = 6;

 function AddHealth (powerUp : int)
 {
     health += powerUp;
     
     if (health>maxHealth)// We can only show six segments //in our HUD.
     {
         health=maxHealth;    
     }        
 }
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

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

3 Lives GUI 1 Answer

Life Bar controlled 1 Answer

Regain health on GUI 2 Answers

Life Player loads another level 1 Answer

How i can add a life for the user if he buy it? 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