使用此代碼,我可以在「玩家」擊中對象時顯示對象的標籤,但是如何讓標籤在碰撞之前出現?我的意思是,例如,當玩家站在物體前方3米處時?在碰撞前顯示對象標籤
private bool showInfo = false;
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Player")
{
showInfo = true;
}
}
void OnCollisionExit(Collision collisionInfo)
{
if (collisionInfo.gameObject.tag == "Player")
{
showInfo = false;
}
}
void OnGUI()
{
if (showInfo)
{
GUIStyle myStyle = new GUIStyle();
Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
myStyle.font = myFont;
myStyle.fontSize = 24;
myStyle.normal.textColor = Color.red;
GUI.Label(new Rect(10, 10, 100, 20), gameObject.tag, myStyle);
}
}
thx,它幫助了很多:) – artur47wien