Unity血条跟随效果

1、OGUI实现血条跟随

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

//将世界坐标换成屏幕坐标
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);
}

2、NGUI实现血条跟随(添加HUD插件)

 实现加血减血显示

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);
}
}

扫描二维码关注公众号,回复: 7437528 查看本文章

脚本加到Cube上控制移动和加减血的显示

3、UGUI血条跟随

public Camera mainCam;
public Transform inPoint;

void Update()
{

//将世界坐标换成屏幕坐标
Vector3 temp = mainCam.WorldToScreenPoint(inPoint.position);
temp.x -= Screen.width * 0.5f;
temp.y -= Screen.height * 0.5f;
transform.localPosition = temp;
}

猜你喜欢

转载自www.cnblogs.com/Damon-3707/p/11639492.html