Question by
KaidaStudios · Sep 10, 2017 at 10:22 AM ·
networkingnetworkplayer
UNET Finding Local Player from script C#
I know that I can use IsLocalPlayer but I am using a GUI equipment menu that is not connected to the player.. and I cant add the "NetworkBehaviour" base to use the IsLocalPlayer because its being taken by "UIBehaviour"..
So my question is! Is there a way to search for the player with NetworkIdentity().IsLocalPlayer? via script? OR how can I use two bases? I wrote this up, but it doesn't seem to work.
protected override void Start()
{
allPlayers = GameObject.FindGameObjectsWithTag("Player");
for (int i = 0; i < allPlayers.Length; i++)
{
if(allPlayers[i].GetComponent<NetworkIdentity>().isLocalPlayer == true)
{
Player = allPlayers[i];
break;
}
}
and this is the start of my script with the base being used.
[AddComponentMenu("UI/Icon Slots/Base Slot"), ExecuteInEditMode, DisallowMultipleComponent]
public class UISlotBase : UIBehaviour, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler {
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612134540im_/https://answers.unity.com/themes/thub/images/avi.jpg)