So i have a button that has a custom script attached to it, which send the button name to player and stores it in an variable inside the player script. The problem is, on the server side, server player the variable is stored and logged out perfectly later when debugging, but when connecting as client and debugging out the variable, its always empty. Like it resets the variable automatically on the client side and i have no clue, because i’m not reseting it anywhere on my code, so is it a bug or do i have to do something specific?
Here is the callback to adding the handler after slot instantiation:
newSlot.transform.Find("Text").GetComponent<Button>().onClick.AddListener(delegate { myplayer.GetComponent<Player>().HasClickedInvItem(slotItemName); });
Here’s the handler function:
public void HasClickedInvItem(string itemName)
{
clickedItemName = itemName;
}
Here’s when i try to print it out, but get always null returned, even though the hasClickedInvItem shows that there’s correct input.
if (Input.GetKeyDown (KeyCode.Z)) {
print("keycode.z selectedItemname (" + clickedItemName+ "); ");
//output: keycode.z selectedItemName null
}