unity机制,自带触发事件函数不受脚本打开关闭影响。
解决小技巧:
事件函数里面增加一个判断,enable,即可
void OnTriggerEnter(Collider other)
{
if (enabled)
{
if (isServer)
{
Debug.Log("isserver");
}
if (isServerOnly)
{
Debug.Log("isserveronly");
}
if (isLocalPlayer)
{
Debug.Log("isLocalPlayer");
}
Debug.Log("OnTrigger执行了");
if (other.CompareTag("cube"))
{
Debug.Log("cube");
NetworkIdentity networkIdentity = other.GetComponent<NetworkIdentity>();
networkIdentity.gameObject.transform.SetParent(transform);
}
}
}