Player Inventory Networking

This commit is contained in:
Melbyj1125
2021-11-17 13:20:00 -06:00
parent 69a946c3ee
commit 17a7cdb1ae
5 changed files with 51 additions and 14 deletions

View File

@@ -1,8 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using MLAPI;
using UnityEngine;
public class PlayerInventory : MonoBehaviour
public class PlayerInventory : NetworkBehaviour
{
//List of items
@@ -12,20 +13,13 @@ public class PlayerInventory : MonoBehaviour
public PlayerStats pStats;
void Awake(){
pStats = GetComponent<PlayerStats>();
DontDestroyOnLoad(transform.parent.gameObject);
pStats = GetComponent<PlayerStats>();
}
//Add item to player Inventory
public void AddItem(Item item, bool ableToAdd){
public void UpdateInventory(Item item, bool ableToAdd){
if(!items.Contains(item) && ableToAdd){
Debug.Log("Item Added");
//Add item to player inventroy list
items.Add(item);
//Equip item
item.Equip(pStats, this.gameObject);
AddItem(item);
}
else if(!ableToAdd && !items.Contains(item)){
//Item cannot be added
@@ -38,6 +32,30 @@ public class PlayerInventory : MonoBehaviour
}
}
public void UpdateEquips(){
foreach(Item item in items){
item.Equip(pStats, this.gameObject);
}
}
//Add item to player Inventory
public void AddItem(Item item){
//Adds and equips Item if it can
items.Add(item);
item.Equip(pStats, this.gameObject);
}
//Add item to player Inventory
public void AddItemNetwork(Item item){
//Adds and equips Item if it can
items.Add(item);
}
//Remove Item player inv
public void RemoveItem(Item item){
if(items.Remove(item)){