Add simple fridge logic
This commit is contained in:
@@ -4,6 +4,7 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public Transform _playerArrivePoint;
|
||||
|
||||
public virtual void Interact(Player player)
|
||||
{
|
||||
Debug.Log("Interact with some object");
|
||||
|
||||
@@ -8,9 +8,13 @@ public class ColaFreezer : BaseInteractableObject
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
var transform = Instantiate(_foodObjectSO.prefab, _playerArrivePoint);
|
||||
var foodObject = transform.GetComponent<FoodObject>();
|
||||
player.SetFoodObject(foodObject);
|
||||
}
|
||||
if (!player.HasFoodObject())
|
||||
{
|
||||
// Spawn new object and set to player
|
||||
var transform = Instantiate(_foodObjectSO.prefab, _playerArrivePoint);
|
||||
var foodObject = transform.GetComponent<FoodObject>();
|
||||
player.SetFoodObject(foodObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Fridge : BaseInteractableObject
|
||||
{
|
||||
private const int _maxCapacity=4;
|
||||
private List<FoodObject> _foodObjects= new List<FoodObject>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
Debug.Log("Interact with Fridge");
|
||||
if (player.HasFoodObject())
|
||||
{
|
||||
if (_foodObjects.Count < _maxCapacity)
|
||||
{
|
||||
_foodObjects.Add(player.GetFoodObject());
|
||||
player.ClearFoodObject();
|
||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
}
|
||||
else
|
||||
Debug.Log($"Fridge is full");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user