59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using Components;
|
|
using Managers;
|
|
using UnityEngine;
|
|
|
|
public class CropInteractiveComponent : InteractiveComponent
|
|
{
|
|
// Crop state
|
|
public int isWatered;
|
|
public new CropInteractable interactable;
|
|
|
|
public CropInteractiveComponent(CropInteractable interactable)
|
|
{
|
|
this.interactable = interactable;
|
|
}
|
|
|
|
public void Harvest()
|
|
{
|
|
if (interactable != null && interactable.cropItem != null)
|
|
{
|
|
Debug.Log("Harvesting Crop:" + interactable.cropItem.itemName);
|
|
// add crop to inventory
|
|
var item = Instantiate(interactable.cropItem);
|
|
PlayerManager.Instance.AddItemToInventorySlot(item);
|
|
// remove crop from tile
|
|
interactable = null;
|
|
// delete visual
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Crop is null");
|
|
}
|
|
}
|
|
|
|
public void Water()
|
|
{
|
|
// Water the crop
|
|
Debug.Log("Watering Crop");
|
|
interactable.isWatered = true;
|
|
}
|
|
|
|
public void SetCrop(CropInteractable tileCropInteractable)
|
|
{
|
|
interactable = tileCropInteractable;
|
|
// change the crop sprite
|
|
// change the crop material
|
|
if (spriteRenderer != null && interactable != null)
|
|
{
|
|
Debug.Log("CROP: SetCrop: " + interactable.name + " Growth Stage: " +
|
|
interactable.currentGrowthStage);
|
|
spriteRenderer.sprite = interactable.growthSprites[interactable.currentGrowthStage - 1];
|
|
}
|
|
}
|
|
|
|
public override void Interact()
|
|
{
|
|
Debug.Log("Crop Interact");
|
|
}
|
|
} |