简体   繁体   中英

MultiPlayer Data best Practice [on hold]

I just want to ask if there is a clean or easy way to save multiple player data in a variable. For example, Player1 data have hp and mana similar to player2. I am new to C# unity. Thanks

I tried to use an array, like int[2] hp and int[2] mana and I think it's not the best way since. I created a Player class with hp and mana and use new but it doesn't work

public class PlayerData
{
    public int hp;
    public int mana;
}

My goal is like this PlayerData[0].hp = 100

Saving multiple player data in a variable? Yes:

List<PlayerData> playerList = new List<PlayerData>();

for(int i = 0; i < playercount; i++)
{
    PlayerData tempPlayer = new PlayerData();

    tempPlayer.hp = 100;
    tempPlayer.mana = 100;

    playerList.Add(tempPlayer);
}

Getting 2nd Player hp:

playerList[1].hp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM