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 question was closed May 29, 2018 at 05:38 AM by omalleym1115 for the following reason:

Gave up yet again.

avatar image
0
Question by omalleym1115 · Aug 27, 2012 at 02:58 AM · guifpshealth

Health and ammo GUI not working on re-spawn

Hi Everyone, I am making a FPS demo and I have a problem. I have a health and ammo GUI working from the old FPS tutorial on this site, but theirs does not work when re-spawning. I have tried different ways and even tried using the unity GUI but to no effect. The GUI's I have work great when I don't die, but right when I re-spawn a character, the GUI are stuck to what they were when I died. It seems to be that the prefab does not let me add the GUIText and the GUITexture to it which is probably my problem but I don't know how to attach it to the prefab through code. If anyone can help me, I would appreciate it. Here is the code for the GUI and my re-spawning of my character:

 var maximumHitPoints = 100.0;
 var hitPoints = 100.0;
 
 var prefabPlayer:Transform;
 var bulletGUI : GUIText;
 var healthGUI : GUITexture;
 private var healthGUIWidth = 0.0;
 
 
 function Awake () {
     healthGUIWidth = healthGUI.pixelInset.width;
 }
 
 function Die () {
     if (die)
         AudioSource.PlayClipAtPoint(die, transform.position);
     Destroy(gameObject);
 }
 
 function LateUpdate () {
     // Update gui every frame
     // We do this in late update to make sure machine guns etc. were already executed
     UpdateGUI();
     if (Input.GetKey("t"))
     Respawn();
     
 }
 
 
 function UpdateGUI () {
     // Update health gui
     // The health gui is rendered using a overlay texture which is scaled down based on health
     // - Calculate fraction of how much health we have left (0...1)
     var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);
 
     // - Adjust maximum pixel inset based on it
     healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;
 
     // Update machine gun gui
     // Machine gun gui is simply drawn with a bullet counter text
     if (machineGun) {
         bulletGUI.text = machineGun.GetBulletsLeft().ToString();
     }
 
 function Respawn() 
 {
     Instantiate(prefabPlayer, transform.position, transform.rotation);
  
 }
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

3D Health Bar - Killing My FPS 1 Answer

Show GUI only when looking at an object? 1 Answer

Can't get Gui Pos on top of Enemy ingame! 0 Answers

How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers

Can't move GUI 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