Add items, Pickup logic works

This commit is contained in:
2024-10-17 01:22:54 +02:00
parent ec487096bf
commit f594bdf112
72 changed files with 7258 additions and 918 deletions

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EmptyCounter : MonoBehaviour, IObjectParentHolder {
[SerializeField] private ObjectSO _objectSo;
[SerializeField] private Transform _counterObjectHandle;
[SerializeField] private bool _shouldSpawnOnInteract;
private Object _currentObject;
public void Interact() {
InteractionBehaviour interactionBehaviour = PlayerController.Instance.InteractionBehaviour;
if (_shouldSpawnOnInteract) {
if (_currentObject == null) {
Transform objectTransform = Instantiate(_objectSo.prefab, _counterObjectHandle);
objectTransform.GetComponent<Object>().setObjectParent(this);
}
}
if (!HasObject()) {
//No item on the counter
//Check player if he has something
if (interactionBehaviour.HasObject()) {
Object obj = interactionBehaviour.GetObject();
obj.setObjectParent(this);
}
else {
//Player has no item
}
}
else {
//Item on Counter
//Check player if he has something
if (interactionBehaviour.HasObject()) {
//Player has something
}
else {
//Player has nothing
//Take the object
GetObject().setObjectParent(interactionBehaviour);
}
}
}
public Transform GetHolderTransform() {
return _counterObjectHandle;
}
public void SetObject(Object obj) {
this._currentObject = obj;
}
public Object GetObject() {
return this._currentObject;
}
public void ClearObject() {
this._currentObject = null;
}
public bool HasObject() {
return this._currentObject != null;
}
}