Changing a player's variable

On the scene, where players connect, there is a button with the scripts "CheckMoney"
public Player player;

public void CheckMoney()
{
  if(player.money >= 5)
        player.money -= 5;
}

There is also a player with a script "Player" on this scene
public int money;
private CheckMoney gb;

private void Start()
{
  gb = GameObject.Find("CheckMoneyGB").GetComponent<CheckMoney>();
  gb.player = this.gameObject.GetComponent<Player>();
}

The problem is that the Check Money script checks the Money variable only for the last player who entered the game

Question - how to correctly implement a variable check for the player who clicked the button?

I will be grateful for your answers :)

Comments

Sign In or Register to comment.