- Home /
Creating and Accessing Unique Variables for Each Player on a Network
Hey, I am trying to create a basic health system for my multiplayer game right now. Basically I want to create a variable that I can then access from other scripts that holds the health amount for each player. I thought I would do this by creating a new variable every time a player is made, like so: (forgive the formatting of the code, for some reason the code tag isn't working for me)
var playerID = 0;
public void CreatePlayer(){
currentNumberOfPlayers++;
connected = true;
var g = (GameObject)Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 1);
g.camera.enabled = true;
camera.enabled = false;
// Here I want to instantiate a new variable for the Player Object I just spawned unique to
// that Player Object Using the Player ID variable
// So for example, when the first one is created, an Variable called "playerhealth1" is made
}
But Im not sure how to go about doing that. Also, how can associate the variable with that gameObject, and then apply damage through another script when using OnCollisionEnter for example.