在Unity3d中如何碰撞触发GUI的显示,然后3秒之后自动消失?(求详细代码)
1个回答
展开全部
public class HillTriggerUI : MonoBehaviour {
public GUISkin guiSkin;
public Texture texBg;
public Texture texNengliangBg;
public Texture texNengliang;
private float lastTime = 0;
void OnGUI() {
if (!guiSkin)
{
Debug.LogError("GUISkin is missing!");
}
GUI.skin = guiSkin;
//显示ZyTypes.UI_TIME 秒数后消失
if (Time.timeSinceLevelLoad - lastTime < ZyTypes.UI_TIME && lastTime != 0) {
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(500, 400, 609, 141)), texBg);
ZhiyueGUI.TranslateFontSize(23, "linefont"); GUI.Label(ZhiyueGUI.TransPos(new Rect(500, 400, 609, 141)), "您从山上跌落,能量值减少!", "linefont");
}
//left //bg
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(60, 300, 40, 540)), texNengliangBg);
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(60, 300+170*(3-g_iNLLvl), 40, 180*g_iNLLvl)), texNengliang);
ZhiyueGUI.TranslateFontSize(19, "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 400, 40, 540)), "体", "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 550, 40, 540)), "力", "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 700, 40, 540)), "值", "tilizhi");
}
//碰撞时显示
void OnTriggerEnter() {
lastTime = Time.timeSinceLevelLoad;
}
}
public GUISkin guiSkin;
public Texture texBg;
public Texture texNengliangBg;
public Texture texNengliang;
private float lastTime = 0;
void OnGUI() {
if (!guiSkin)
{
Debug.LogError("GUISkin is missing!");
}
GUI.skin = guiSkin;
//显示ZyTypes.UI_TIME 秒数后消失
if (Time.timeSinceLevelLoad - lastTime < ZyTypes.UI_TIME && lastTime != 0) {
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(500, 400, 609, 141)), texBg);
ZhiyueGUI.TranslateFontSize(23, "linefont"); GUI.Label(ZhiyueGUI.TransPos(new Rect(500, 400, 609, 141)), "您从山上跌落,能量值减少!", "linefont");
}
//left //bg
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(60, 300, 40, 540)), texNengliangBg);
GUI.DrawTexture(ZhiyueGUI.TransPos(new Rect(60, 300+170*(3-g_iNLLvl), 40, 180*g_iNLLvl)), texNengliang);
ZhiyueGUI.TranslateFontSize(19, "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 400, 40, 540)), "体", "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 550, 40, 540)), "力", "tilizhi");
GUI.Label(ZhiyueGUI.TransPos(new Rect(60, 700, 40, 540)), "值", "tilizhi");
}
//碰撞时显示
void OnTriggerEnter() {
lastTime = Time.timeSinceLevelLoad;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询