put cola in basket

This commit is contained in:
Vladimir Koshevarov
2023-03-05 14:01:39 +02:00
parent 905d159f4e
commit 5ac0f1c82e
4 changed files with 38 additions and 15 deletions
@@ -8,14 +8,14 @@ public class ColaFreezer : BaseInteractableObject
public override void Interact(Player player)
{
//if (!player.IsHoldContainer())
//{
// //player.BuyObject(_sellableItemSO);
// // Spawn new object and set to player
// var transform = Instantiate(_sellableItemSO.prefab, _playerArrivePoint);
// var foodObject = transform.GetComponent<FoodItem>();
// player.SetFoodObject(foodObject);
//}
if (player.IsHoldContainerItem())
{
var transform = Instantiate(_sellableItemSO.prefab, player.GetContainerItem().transform);
var sellableItem = transform.GetComponent<SellableItem>();
var container = player.GetContainerItem();
container.AddItem(sellableItem);
}
}
}
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
public class ContainerItem : MonoBehaviour
@@ -5,8 +6,30 @@ public class ContainerItem : MonoBehaviour
[SerializeField]
private ContainerSO _containerSO;
private List<SellableItem> _items;
private void Start()
{
_items = new List<SellableItem>();
}
public ContainerSO GetContainerObjectSO()
{
return _containerSO;
}
public void AddItem(SellableItem item)
{
if (_containerSO.CurrentItemsCount < _containerSO.MaxCapacity)
{
Debug.Log($"Player put to container a {item.GetSellableItemSO().objectName}");
_items.Add(item);
_containerSO.CurrentItemsCount = _items.Count;
}
else
{
Debug.Log("Container is full");
}
}
}
@@ -3,10 +3,10 @@ using UnityEngine;
public class SellableItem : MonoBehaviour
{
[SerializeField]
private SellableItemSO _foodObjectSO;
private SellableItemSO _sellableItemSO;
public SellableItemSO GetFoodObjectSO()
public SellableItemSO GetSellableItemSO()
{
return _foodObjectSO;
return _sellableItemSO;
}
}