55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
public class EmptyCounter : BaseCounter {
|
|
|
|
[SerializeField] private ObjectSO _objectSo;
|
|
|
|
[SerializeField] private bool _shouldSpawnOnInteract;
|
|
public void SetItem(ObjectSO objectSo, float price = 0, bool isBroken = false) {
|
|
//Set the item on the counter
|
|
if(_currentObject != null) {
|
|
Destroy(_currentObject.gameObject);
|
|
}
|
|
Transform objectTransform = Instantiate(objectSo.prefab, _counterObjectHandle);
|
|
|
|
Object obj = objectTransform.GetComponent<Object>();
|
|
obj.ObjectSo = objectSo;
|
|
obj.PaidPrice = price;
|
|
obj.IsBroken = isBroken;
|
|
obj.setObjectParent(this);
|
|
}
|
|
|
|
public override void Interact(InteractionBehaviour interactionBehaviour) {
|
|
if (_shouldSpawnOnInteract) { //Debug
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |