evershade/Assets/Scripts/Components/CropInteractiveComponent.cs

71 lines
1.8 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;
}
// Crop methods
public void Grow()
{
// Grow the crop
}
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 void SetInteractable(Interactable tileInteractable)
{
interactable = tileInteractable as CropInteractable;
}
public override void Interact()
{
Debug.Log("Crop Interact");
}
}