UI button to gameobject

Options

Hey,

I'm really sorry for my bad english.

I'm new to this stuff and have no clue what i'm doing. I have a question about my UI.

I'm trying to create a buymenu like in csgo so in my head i tought i just make buttons in the UI and make them set the gun the player prefab has on him visable. but it doesn't update on the screen of the other client.

so i have this itemindex for the equipItem function. I made a new function called BuyItem got the int of the correct item but it doesn't wanna make it active.

I hope someone can help me :)

greetings sander

Code:

public void BuyItem(int _index)

{

itemIndex = _index; 


Debug.Log("Tried to buy item");

if (itemIndex == 0)

{


Debug.Log("return item number " + itemIndex); 

items[itemIndex].itemGameObject.SetActive(true);

}

if(itemIndex == 1)

    {

Debug.Log("Return item number: " + itemIndex);

items[itemIndex].itemGameObject.SetActive(true); 

    }

if (PV.IsMine)

{

Hashtable hash = new Hashtable();

hash.Add("itemIndex", itemIndex);

PhotonNetwork.LocalPlayer.SetCustomProperties(hash);

}

}

public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)

{

if (!PV.IsMine && targetPlayer == PV.Owner)

{


BuyItem((int)changedProps["itemIndex"]);

EquipItem((int)changedProps["itemIndex"]);

}

}

public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)

{

if (!PV.IsMine && targetPlayer == PV.Owner)

{


BuyItem((int)changedProps["itemIndex"]);

EquipItem((int)changedProps["itemIndex"]);

}

}

Answers

  • tleylan
    Options

    Hi @akanostress

    It would help a lot if you formatted your code as in the example below.

    private void ExampleMethod()
    {
       Debug.Log("ExampleMethod");
    }
    

    From what I can tell you are trying to affect other clients through the use of OnPlayerPropertiesUpdate. I haven't done that but it appears to be used regularly so I would hunt for several examples that update player properties and imitate one of them.