Hello everyone!
I’m trying to assign client authority to gameobject which has trigger. When local player enters the trigger and presses button, OnTriggerStay calls function on local player script and this function calls command to assign client authority. When i have one object with trigger it works perfectly, but when i have more than one trigger, authority assigns to random gameobject.
Object with trigger:
public void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.F))
{
playerScript.instance.assignAuth();
}
}
Local player:
public void assignAuth()
{
if (!isLocalPlayer)
return;
CmdAssignAuthority();
}
[Command]
void CmdAssignAuthority()
{
triggerOwner.instance.gameobject.GetComponent<NetworkIdentity>().AssignClientAuthority(GetComponent<NetworkIdentity>().connectionToClient);
}
So, i need to get Network Identity component from gameobject which was triggered by local player.
I will appreciate any ideas
p.s. right now, as i understand, CmdAssignAuthority() takes random gameobject which has script triggerOwner on it.