Unity血條跟隨效果

一、OGUI實現血條跟隨ide

public Camera mainCam;
public Transform inPoint;
private float hSliderValue;
private void OnGUI()
{spa

//將世界座標換成屏幕座標
Vector3 temp = mainCam.WorldToScreenPoint(inPoint.position);
GUI.color = Color.red;
//GUI.Label(new Rect(temp.x, Screen.height-temp.y, 100, 20), "唐三");
hSliderValue = GUI.HorizontalSlider(new Rect(temp.x,Screen.height- temp.y, 100, 30), hSliderValue, 0.0f, 10.0f);
}插件

二、NGUI實現血條跟隨(添加HUD插件)3d

 

 實現加血減血顯示orm

 

 

public HUDText hud;
public float speed;
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
transform.position += new Vector3(h * Time.deltaTime * speed, v * Time.deltaTime * speed, 0);
if (Input.GetMouseButtonDown(0))
{
hud.Add("+100",Color.green,0.5f);
}
if (Input.GetMouseButtonDown(1))
{
hud.Add("-100", Color.red, 0.5f);
}
}blog

腳本加到Cube上控制移動和加減血的顯示it

三、UGUI血條跟隨io

 

public Camera mainCam;
public Transform inPoint;

void Update()
{form

//將世界座標換成屏幕座標
Vector3 temp = mainCam.WorldToScreenPoint(inPoint.position);
temp.x -= Screen.width * 0.5f;
temp.y -= Screen.height * 0.5f;
transform.localPosition = temp;
}transform

相關文章
相關標籤/搜索