add WeaponInventory in Player.cs

This commit is contained in:
DerTyp187
2022-01-24 19:23:55 +01:00
parent 41847c9ca8
commit 4fdc6aad3a
3 changed files with 44 additions and 15 deletions

View File

@@ -3,6 +3,12 @@ using System.Collections.Generic;
using UnityEngine;
using Mirror;
public struct WeaponItem
{
public string name;
public int ammo;
}
public class Player : NetworkBehaviour
{
Lobby lobby;
@@ -25,21 +31,11 @@ public class Player : NetworkBehaviour
private int kills;
private int deaths;
public readonly SyncList<WeaponItem> weaponInventory = new SyncList<WeaponItem>();
private void Start()
{
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
/*GameManager = GameObject.Find("MatchController");
gameMaster = GameManager.GetComponent<GameMaster>();
if (isServer)
{
health = defaultHp;
gameMaster.RegisterPlayer(GetComponent<Player>());
//respawnPos(gameMaster.RespawnRequest(this.gameObject, team.teamID));
}*/
}
private void Update()
@@ -51,6 +47,11 @@ public class Player : NetworkBehaviour
playerUIController.showHit();
}
if (Input.GetKeyDown(KeyCode.O))
{
CmdAddWeaponItem(new WeaponItem());
}
}
}
public override void OnStartLocalPlayer()
@@ -59,6 +60,15 @@ public class Player : NetworkBehaviour
}
#region INVENTORY
[Command]
public void CmdAddWeaponItem(WeaponItem weaponItem)
{
weaponInventory.Add(weaponItem);
}
#endregion
public void SetName(string oldName, string newName)
{
username = newName;