• 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 N1warhead · Jan 07, 2015 at 02:17 AM · uigui

Floating Enemy Health Bars?

Hey how would I go about making a floating enemy health bar?

I only want it to work if you are aiming at the player. (T$$anonymous$$s is for an online game).

W$$anonymous$$ch the Networking part isn't the part I need help with.

Just would like to know how to make it look like in the image (Just appear under the player) if you aim at $$anonymous$$m.

Such as the one in the image.

(I'm not familiar with t$$anonymous$$s new UI) so I'm kind of lost. Right now I have a World Space Canvas just on my enemy, if an object runs into it, it gets covered up and is always on.

alt text

screen8.jpg (67.9 kB)
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
1

Answer by Cherno · Jan 07, 2015 at 02:24 AM

In simple terms:

  1. Raycast from the Camera forward, and store the transform.position of the enemy object if the ray $$anonymous$$ts one. If you need to access any variables on the enemy object, store these as well (or store the whole object)

  2. Convert the enemy object's position into screen space coordinates.

  3. Use these coordinates to draw the health bar on screen. For the specific health value, access the necessary variables from 1).

Comment
Add comment · Show 3 · 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 N1warhead · Jan 07, 2015 at 02:27 AM 0
Share

How do I convert a vector3 position into screen space coordinates? And this is for the new UI?

(Sorry for the stupid questions LOL).

avatar image Cherno · Jan 07, 2015 at 02:48 AM 0
Share

You use Camera.WorldToScreenPoint to convert the coordinates. If this is for the new UI I can not answer since I haven't used it myself, but I assume that it needs the screen coordinates to know where to draw the health bar texture :)

avatar image SnStarr · Jan 10, 2015 at 01:32 AM 0
Share

Try creating your health bar, and storing it above the players head, with a collider of some sort, child it to the player and it will follow him around. Setup a raycast function to players collider. You can setup a function in your script to change the alpha of the texture to 0 unless a raycast hits the collider of the player, then it will set the alpha back to normal so the health bar appears. You can also add a fade in fade out effect after the aiming is complete or begun. Im new ot scripting also, but im pretty sure this is the simple way to go about it. If i am wrong someone will tell me. Happy hunting.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

26 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

Related Questions

Multiple Cars not working 1 Answer

Create big city for car game? 2 Answers

Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers

Gameover function calling before game ends help 2 Answers

What is a good unityscript writing program? 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