设置碰撞体,例如cube
将脚本挂载在物体上,碰撞显示text文章来源:https://www.toymoban.com/news/detail-506305.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
public class ColliderSign : NetworkBehaviour
{
public GameObject text;
void Start()
{
text.SetActive(false);
}
private void OnCollisionEnter(Collision collision) {
if(collision.gameObject.GetComponent<PlayerControl>().IsLocalPlayer){
text.SetActive(true);
}
}
private void OnCollisionStay(Collision collision) {
if(collision.gameObject.GetComponent<PlayerControl>().IsLocalPlayer){
text.SetActive(true);
}
}
private void OnCollisionExit(Collision collision)
{
if(collision.gameObject.GetComponent<PlayerControl>().IsLocalPlayer){
text.SetActive(false);
}
}
}
碰撞体的子物体,例如3dObject-legacy-text
绑定代码,使文字一直正对屏幕(相机)文章来源地址https://www.toymoban.com/news/detail-506305.html
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtMainCamera : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.LookAt(transform.position + Camera.main.transform.rotation *
Vector3.forward,Camera.main.transform.rotation * Vector3.up);
}
}
到了这里,关于unity3d人物碰撞提示文字的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!