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 Robomaster · Sep 04, 2012 at 10:56 PM · guienemyfloat

Enemy Position

Hello i was wondering if anyone could direct me to a link or help me on how to create a GUI button that floats right above the enemys head. Thanks in advance!

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

2 Replies

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

Answer by AlucardJay · Sep 05, 2012 at 05:14 AM

There are 2 methods you could use. One I don't recommend is drawing a GUITexture aligned to the player/character. Another method is the 'floating health bar'. Create a plane above the character as a child of that character. Write a very short script that tells the plane to face the camera, or as here rotate to the same angle as the camera =]

http://answers.unity3d.com/questions/195711/minion-floating-healthbar-over-the-head.html

http://answers.unity3d.com/questions/20697/how-to-create-billboarding-planes.html

http://forum.unity3d.com/threads/26014-Health-bar-over-enemy

https://www.google.com/search?q=unity+floating+health+bar

  • I had to fix your title, it was bugging me =] )*

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 Robomaster · Sep 05, 2012 at 05:27 AM 0
Share

lololol thanks ill take a look at it tommorrow im to tired right now to take a look at it. Thanks i really appericate the help :)

avatar image Screenhog · Sep 05, 2012 at 03:13 PM 0
Share

Yep, that's a great option, too. It also has the advantage of making the health bar's size change depending on how far you are away from the enemy.

avatar image Robomaster · Nov 10, 2012 at 12:35 AM 0
Share

lol sorry about that :p

avatar image
1

Answer by Screenhog · Sep 04, 2012 at 11:42 PM

I'd start here:

http://docs.unity3d.com/Documentation/ScriptReference/Camera.WorldToScreenPoint.html

Now, you just need a Vector3 point where you want the GUI button to float.

Comment
Add comment · Show 4 · 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 Robomaster · Sep 05, 2012 at 12:01 AM 0
Share

ohh okay so would this work

using UnityEngine; using System.Collections;

public class example : $$anonymous$$onoBehaviour {

public Transform target;

target = GameObject.Find("Orge");

void OnGUI(){

 Vector3 screenPos = 

camera.WorldToScreenPoint(target.position);

if (GUI.Button(new Rect(target.postion), "Attack")){

(Code goes here) } }

avatar image Screenhog · Sep 05, 2012 at 12:12 AM 0
Share

No, because your Rect needs to be four floats. Target.position merely tells you where the center of the button needs to be. You need to define the left point, top point, width, and height of the button based on this.

avatar image Robomaster · Sep 05, 2012 at 12:16 AM 0
Share

ohh okay thanks so if i wanted it to be floating above the enemys head how would i code the left point, and top point

avatar image Screenhog · Sep 05, 2012 at 04:44 AM 0
Share

The point you know is the center of your rectangle, right? So, your left and top point will be relative to that.

Let's say you want your Rect to be 100 pixels wide. If screenPos = camera.WorldToScreenPoint(target.position), then screenPos.x-50 would be your left point (50 because it's 100 divided by 2). Your Rect will look something like this:

Rect(screenPos.x-50, screenPos.y-30, 100, 60)

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

9 People are following this question.

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

Related Questions

Deduct health on collision 2 Answers

String not showing up in GUI label 1 Answer

C# Floating Health Bar 2 Answers

How To Make A Floating Health Bar 1 Answer

GUI follow enemy object 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