interactable

This commit is contained in:
Janis
2023-03-04 15:53:47 +01:00
parent ae0b21f9e9
commit 5f08865a2b
17 changed files with 506 additions and 357 deletions

View File

@@ -0,0 +1,66 @@
using UnityEngine;
public enum FieldState
{
EMPTY,
DEAD,
GROWING,
HARVESTABLE,
}
public class Field : Building
{
public Crop crop;
public SpriteRenderer currentCropSpriteRenderer;
public int daysSincePlanted;
public bool isWatered = false;
public FieldState state = FieldState.EMPTY;
private void Start()
{
TimeManager.OnDayChanged += AddDay;
}
private void SetSprite(Sprite sprite)
{
if (currentCropSpriteRenderer)
{
currentCropSpriteRenderer.sprite = sprite;
currentCropSpriteRenderer.drawMode = SpriteDrawMode.Tiled;
currentCropSpriteRenderer.size = new Vector2(10, 10); // TODO: Make this dynamic
}
}
private void AddDay()
{
if (crop && isPlaced && state != FieldState.DEAD)
{
if (!isWatered)
state = FieldState.DEAD;
else
{
daysSincePlanted++;
SetSprite(crop.sprites[daysSincePlanted]);
}
}
}
public void Plant(Crop newCrop)
{
daysSincePlanted = 0;
state = FieldState.GROWING;
crop = newCrop;
SetSprite(crop.sprites[0]);
}
public override void OnPlace()
{
Plant(null);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53c8af14dae8dbe4e95cda372289f89e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
// Interactable object which lets the player plant & harvest a seed
using UnityEngine;
public class FieldController : Interactable
{
public Field field;
public Crop testCrop;
public override void OnInteract()
{
Debug.Log("Interacting with field");
field.Plant(testCrop);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b43d0d1aa7cd2c4db0db026202eb972
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: