Question by
lqvinh2 · May 22, 2018 at 04:17 AM ·
networkingnetworkplayerhealth
[Multiplayer - UnityEngine.Networking; NetworkBehaviour] OnMouseEnter() not work of game object spawn from NetworkServer.Spawn(go); only work on Player hasAuthority, client can not access this function. any help ?
using UnityEngine; using UnityEngine.Networking;
public class Spawn_Cube_Map : NetworkBehaviour { [SerializeField] GameObject cube_prefab;
[SerializeField]
GameObject obParent;
float Timer = 0.5f;
// Use this for initialization
void Start()
{
}
bool isRunFirst = true;
// Update is called once per frame
void Update()
{
Timer -= Time.deltaTime;
if (Timer <= 0)
{
Timer = 2f;
CmdSpawn();
}
}
[Command]
void CmdSpawn()
{
RpcSpawn2();
}
[ClientRpc]
void RpcSpawn2()
{
if (isServer)
{
GameObject go = Instantiate(cube_prefab, pos, rotation);
NetworkServer.Spawn(go);
go.transform.SetParent(obParent.transform);
}
}
} // 2 OnMouseEnter() of object [go] spawn from NetworkServer.Spawn(go) not wroking void OnMouseEnter() { if (isServer) { print("OnMouseEnter isServer :"); } if (isLocalPlayer) { print("OnMouseEnter isLocalPlayer :" ); }
if (hasAuthority)
{
print("OnMouseEnter hasAuthority :");
}
print("line-normal");
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612163148im_/https://answers.unity.com/themes/thub/images/avi.jpg)