GUI

Bar follow gameObject

February 17, 2013   ·   0 Comments

Screen Shot 2013-02-17 at 10.39.37 AM
using UnityEngine;
using System.Collections;

public class GUIWithGameObject : MonoBehaviour {

public int healthBarWidth=200;
public int healthBarHeight =21;
	
public float healthBarPercentage=0.2f;

public Texture2D  healthBarTexture ;
private Vector3  screenPosition;
	

 

		void Update (){
		
		    screenPosition = Camera.main.WorldToScreenPoint(transform.position);
		
		    screenPosition.y = Screen.height - screenPosition.y;
		
		}
		
		 
		
		void OnGUI (){  
		int t_hight=50;    
		 GUI.Box(new Rect(0,0, healthBarWidth*healthBarPercentage,healthBarHeight), healthBarTexture);
		
            GUI.Button(new Rect(screenPosition.x - healthBarWidth/2, screenPosition.y - healthBarHeight/2-t_hight, healthBarWidth, healthBarHeight),"femur");   
	//	    GUI.Button(new Rect(screenPosition.x - healthBarWidth/2, screenPosition.y - healthBarHeight/2, healthBarWidth, healthBarHeight));   
		    GUI.Label(new Rect(screenPosition.x - healthBarWidth/2, screenPosition.y-t_hight, 100,20), "how are you");
		
		 
		
		}
}


shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon