【Unity】用NGUI實現血條和傷害顯示
阿新 • • 發佈:2019-01-22
using UnityEngine;
using System.Collections;
public class create_HP : MonoBehaviour {
public GameObject HP_prefab; //預設的血條
public Transform create; //生成的地點
public GameObject hudtext; //頭頂傷害顯示預設
//Use this for initialization
void Start()
{
GameObject go= GameObject.Instantiate(HP_prefab, HP_prefab.transform.position, Quaternion.identity) as GameObject;
go.transform.parent = create;
go.transform.localPosition = Vector3.zero;
}
//Update is called one per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject hud = GameObject.Instantiate(hudtext, hudtext.transform.position, Quaternion.identity) as GameObject;
hud.transform.parent = create;
hud.transform.localPosition = Vector3.zero;
}
}
using System.Collections;
public class create_HP : MonoBehaviour {
public GameObject HP_prefab; //預設的血條
public Transform create; //生成的地點
public GameObject hudtext; //頭頂傷害顯示預設
//Use this for initialization
void Start()
{
GameObject go= GameObject.Instantiate(HP_prefab, HP_prefab.transform.position, Quaternion.identity) as GameObject;
go.transform.parent = create;
go.transform.localPosition = Vector3.zero;
}
//Update is called one per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
GameObject hud = GameObject.Instantiate(hudtext, hudtext.transform.position, Quaternion.identity) as GameObject;
hud.transform.parent = create;
hud.transform.localPosition = Vector3.zero;
}
}