public void SetIndex(int index) { this.index = index; var gamePlanted = PlayerPrefs.GetInt(PlantPref(), -1); var plantType = PlayerPrefs.GetInt(PlantPref() + "-type", -1); Status = PlantStatus.Empty; renderer.sprite = emptySprite; if (gamePlanted > -1) { plant = plantTypes.GetPlant(plantType); Status = PlantStatus.Planted; renderer.sprite = growingSprite; turnsLeft = plant.TurnsToGrow - (gameManager.GamesPlayed - gamePlanted); if (turnsLeft <= 0) { Status = PlantStatus.Ready; renderer.sprite = grownSprite; } } }
public override void _Input(InputEvent @event) { if (PlayerColliding) { if (Input.IsActionJustPressed("Player_Action")) { if (PlayerBody.Inventory.HeldSlot < PlayerBody.Inventory.Items.Count) { HeldItem = PlayerBody.Inventory[PlayerBody.Inventory.HeldSlot]; if (HeldItem == Tools.GetTool(0) && State == states.UnCropped) { State = states.Cropped; } if (HeldItem.Type == Item.Types.Seed) { if (State == states.Cropped) { State = states.Planted; switch (HeldItem.ID) { case 0: CurrentPlant = Plants.GetPlant(0); PlayerBody.Inventory.Remove(PlayerBody.Inventory[PlayerBody.Inventory.HeldSlot]); break; case 1: CurrentPlant = Plants.GetPlant(1); PlayerBody.Inventory.Remove(PlayerBody.Inventory[PlayerBody.Inventory.HeldSlot]); break; } } } if (HeldItem == Tools.GetTool(1) && State == states.Planted) { State = states.Watered; PlantGrownTimer.Start(); } } if (PlayerBody.Inventory.Items.Count < PlayerBody.Inventory.Items.Capacity) { if (State == states.Grown) { PlayerBody.Inventory.Gain(CurrentPlant.Crop); CurrentPlant = null; State = states.UnCropped; } } } } }