mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-03-23 18:24:16 -05:00
54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerInventory : MonoBehaviour
|
|
{
|
|
|
|
//List of items
|
|
[SerializeField] List<Item> items;
|
|
|
|
//Scripts
|
|
public PlayerStats pStats;
|
|
|
|
void Awake(){
|
|
pStats = GetComponent<PlayerStats>();
|
|
DontDestroyOnLoad(transform.parent.gameObject);
|
|
|
|
}
|
|
|
|
public void AddItem(Item item, bool ableToAdd){
|
|
if(!items.Contains(item) && ableToAdd){
|
|
Debug.Log("Item Added");
|
|
items.Add(item);
|
|
item.Equip(pStats, this.gameObject);
|
|
}
|
|
else if(!ableToAdd && !items.Contains(item)){
|
|
Debug.Log("Item Cannot Be Added");
|
|
}
|
|
else{
|
|
Debug.Log("Item Removed");
|
|
RemoveItem(item);
|
|
}
|
|
}
|
|
|
|
public void AddSpecialItem<T>(T itemCandidate) { // Unless we don't want the four special items to be handled by inventory/inventory manager?
|
|
if (itemCandidate is Item) {
|
|
items.Add(itemCandidate as Item);
|
|
}
|
|
}
|
|
|
|
|
|
public void RemoveItem(Item item){
|
|
if(items.Remove(item)){
|
|
item.Unequip(pStats, this.gameObject);
|
|
}
|
|
}
|
|
|
|
public List<Item> GetItems(){
|
|
return items;
|
|
}
|
|
|
|
|
|
}
|