Add simple fridge logic
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FollowPath : MonoBehaviour
|
||||
{
|
||||
public enum MovementTypes
|
||||
{
|
||||
Moveing, Lerping
|
||||
|
||||
}
|
||||
|
||||
public MovementTypes MovementType = MovementTypes.Moveing;
|
||||
public MovementPath MyPath;
|
||||
public float speed = 1;
|
||||
public float maxDistance = .1f;
|
||||
|
||||
public IEnumerator<Transform> pointInPath;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (MyPath == null)
|
||||
{
|
||||
Debug.Log("path not attached");
|
||||
return;
|
||||
}
|
||||
pointInPath = MyPath.GetNextPathPoint();
|
||||
pointInPath.MoveNext();
|
||||
if (pointInPath.Current == null)
|
||||
{
|
||||
Debug.Log("need points");
|
||||
return;
|
||||
}
|
||||
transform.position = pointInPath.Current.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (pointInPath == null || pointInPath.Current == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MovementType == MovementTypes.Moveing)
|
||||
{
|
||||
transform.position = Vector3.MoveTowards(transform.position, pointInPath.Current.position, Time.deltaTime * speed);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, pointInPath.Current.position, Time.deltaTime * speed);
|
||||
}
|
||||
|
||||
var distanceSqare = (transform.position - pointInPath.Current.position).sqrMagnitude;
|
||||
if (distanceSqare < maxDistance * maxDistance)
|
||||
{
|
||||
pointInPath.MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a17411f0f5c4b764fb4afd65c74cbcb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -120,23 +120,6 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFoodObject(FoodObject foodObject)
|
||||
{
|
||||
foodObject.transform.parent = _holdPoint;
|
||||
foodObject.transform.localPosition = Vector3.zero;
|
||||
_foodObject = foodObject;
|
||||
Debug.Log($"player hold {foodObject.GetFoodObjectSO().name}");
|
||||
|
||||
}
|
||||
public FoodObject GetFoodObject()
|
||||
{
|
||||
return _foodObject;
|
||||
}
|
||||
public void ClearFoodObject()
|
||||
{
|
||||
_foodObject = null;
|
||||
}
|
||||
|
||||
private TaskStatus MoveToPoint()
|
||||
{
|
||||
SetPlayerAnimation(AnimationStates.Walking);
|
||||
@@ -257,4 +240,27 @@ public class Player : MonoBehaviour
|
||||
return attr != null;
|
||||
}
|
||||
|
||||
|
||||
public void SetFoodObject(FoodObject foodObject)
|
||||
{
|
||||
foodObject.transform.parent = _holdPoint;
|
||||
foodObject.transform.localPosition = Vector3.zero;
|
||||
_foodObject = foodObject;
|
||||
Debug.Log($"player hold {foodObject.GetFoodObjectSO().name}");
|
||||
|
||||
}
|
||||
public FoodObject GetFoodObject()
|
||||
{
|
||||
return _foodObject;
|
||||
}
|
||||
public void ClearFoodObject()
|
||||
{
|
||||
Destroy(_foodObject.gameObject);
|
||||
_foodObject = null;
|
||||
}
|
||||
|
||||
public bool HasFoodObject()
|
||||
{
|
||||
return _foodObject != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user