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 /
avatar image
0
Question by EliteHedgehog56 · Dec 24, 2017 at 03:37 AM · textfloatdisableenable

displaying text problem

I have made this script for my splitscreen tank game, where if the player looses all five lives their tank prefab would be disabled, I have set up a text variable for both the remaining health and lives, but for some reason when the tank runs out of lives and is disabled the text doesn't change to 0. Has it got something to do with the disabling of the tank or is it something else?

here is the script var spawneffect : Transform; var deatheffect : Transform; var SpawnPoint : Transform; var respawn : boolean = false; var health : float = 90; var lives : float = 5; var outoflives : boolean = false; var gotlives : boolean = true; var healthtext : UI.Text; var livestext : UI.Text;

   function Damage(dmg:float){
  health -= dmg;
  }
  
  function Update (){
  if (healthtext)healthtext.text = health.ToString();
  if (livestext)livestext.text = lives.ToString();
  if (gotlives){
  if(health <=0){
 
    Instantiate (deatheffect,transform.position,transform.rotation);
 
   transform.position = SpawnPoint.position;
  
     Instantiate (spawneffect,transform.position,transform.rotation);
 
   var audio: AudioSource = GetComponent.<AudioSource>();
     audio.Play();
     audio.Play(44100);
   lives -= 1;
   health += 100;
  }
  }
 
  if (lives <=0){
  outoflives = true;
  gotlives = false;
  }
 
  }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Larry-Dietz · Dec 24, 2017 at 04:35 AM

From looking at your script, I would expect the text to be displaying 0 Lives and 100 Health after losing your final life.

Is this what you are seeing?

If this is what you are seeing, and you are expecting/wanting Health to also be showing 0, then in your if Health block, where you are setting Health back to 100, just change it to the code below. Currently when your health dropped to or below 0 on the final life, and it decrements lives to 0, it is also setting health to 100.

 if(lives>)
    health+=100;

Hope this helps, -Larry

Comment
Add comment · Show 2 · 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 EliteHedgehog56 · Dec 24, 2017 at 05:34 AM 0
Share

@Larry-Dietz well to clarify my question, when the tank loses it's final life, I want it to be able to display 0 on both the lives and health bar, but at the moment when the tank loses it's final life and is disabled it doesn't change the life bar text to zero, the health text stays on zero like it should but the life bar text remains on one even though the life float has been reduced to 0, my guess it's something to do with disabling the tank so the script is unable to change the text.

avatar image Larry-Dietz EliteHedgehog56 · Dec 24, 2017 at 05:50 AM 0
Share

I don't see the code that is disabling the tank. If it is getting disabled before the update statement runs again after lives hits 0, then you are right. That would cause exactly what you are describing.

$$anonymous$$y first thought would be that since you are disabling the tank when lives hit 0, wherever that disabling is happening just explicitly set that text object to 0 at that point.

-Larry

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

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

Related Questions

Load a GameObject that is outside of script and set it active at the same time 1 Answer

random respawn and respawn delay 1 Answer

Disable/Enable Buttons and Text plz help jc 1 Answer

Can't disable/enable GameObject Component (C#) 1 Answer

Goal disabled while coins are present. 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