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 Tabu · Dec 15, 2011 at 08:25 PM · guitexturehealthbarfloating

Minion floating healthbar over the head

Hey I am trying to make healthbars floating over the head of some soldiers, and I am trying to figure out what way to do this best.

Right now I am using a plane, whos size is dependent on the health left for the minion. It then looks at the camera.. however, since the camera is freefloating and can rotate around all axis, minions at the edge of the screen get a twisted healtbar, that does not look as I want it to.

I have tried with GUITexture, but could not really get that to work effeciently, as soon as I attach the GUITexture to my minions, it dissapears, and as far as I can understand this is bacuse the minions are not positioned (transform) with x,y between 0 and 1? I simply cant get it to do what I want it to. Also gui draw texture does not seem to be the correct way to go, or maybe I am not clever enough? :) I cant get this to stay at the correct position over the minions head.

So I am asking here, if anyone have some ideas, and experiences that they could share on the topic of creating floating healthbars?

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 cj_coimbra · Dec 15, 2011 at 08:56 PM 0
Share

Have it as a GUI element displayed at the corresponding position on screen space.

A starting idea would be:

screenPosition = Camera.main.WorldToScreenPoint(myObject.transform.position);

GUI.DrawTexture(new Rect(screenPosition.x, Screen.height - screenPosition.y - 96, 96, 64), someTexture);

avatar image Tabu · Dec 18, 2011 at 07:38 PM 0
Share

Yes, I tried this, and it "kinda work" however, following the scale in 3d space is not really possible, so either the healtbars are way to big, or way to small. I dont know if there is any way to make sure that the scale in the gui space, follow the scale in 3d space.

1 Reply

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

Answer by Tabu · Dec 27, 2011 at 04:54 PM

So, I figured this out, and will here come with the sollution that did the trick for me. First of, the stuff that did not work for me was having doing gui.drawtexture. I almost got this working, but since I have a free floating camera, the size of the gui, would never fit to the size of the objects in the scene, it would almost fit when I rsized it basted on the distance to the camera, but as soon as I came in closer than 70 units from the 3d object, the size would no longer fit, and I would get all sorts of wierd results. (And since I am a Artist, doing complicated math is not really an option for me)

So I went back to my initial attempt, where I have a 3d object, that also have a LookAt towards the camera. As previaously stated, this made everything work fine, untill the camera came close to the units, as soon as the healthbars went a bit to the sides, the healthbar lookat direction would cause the healtbar to be sideways, and not looking straight at the camera. What I tried at last, and what I should have figured out in the beginning, was to just take the rotation of the camera and applie it to the healthbar... and there you have it.. a freefloating healthbar, looking straight at the camera.

 using UnityEngine;
 using System.Collections;
 
 public class LookAtCamera : MonoBehaviour
 {
      private Camera theCamera;
 
     // Use this for initialization
 
     void Start()
     {
         theCamera = Camera.main; 
     }
 
     // Update is called once per frame
 
     void Update()
     {
         transform.rotation = theCamera.transform.rotation;
     }
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Issue with GUITexture width. 1 Answer

Floating GUITexture jumpy and buggy 1 Answer

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

how would you make guiTexture.pixcelInset.width a variable? 1 Answer

Yet another health bar request 2 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