Forum begins after the advertisement:
[Part 29] Can’t plant seeds after adding the Stamina
Home › Forums › Video Game Tutorial Series › Creating a Farming RPG in Unity › [Part 29] Can’t plant seeds after adding the Stamina
- This topic has 3 replies, 3 voices, and was last updated 1 week, 4 days ago by Jhan Khendrick Perez.
Viewing 5 posts - 1 through 5 (of 5 total)
-
AuthorPosts
-
January 6, 2025 at 11:49 am #17041::
After following the Part 29 on the Stamina part, I can’t seem to plant seeds, even though doing it like
if (selectedSoil != null) { EquipmentData.ToolType toolType = equipmentTool.toolType; switch (toolType) { case EquipmentData.ToolType.HandTrowel: PlayerStats.UseStamina(10); selectedSoil.Interact(); return; case EquipmentData.ToolType.WateringCan: PlayerStats.UseStamina(10); selectedSoil.Interact(); return; } selectedSoil.Interact(); return; }
Didn’t resolve the issue
View post on imgur.com
using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class PlayerInteraction : MonoBehaviour { PlayerMove playerMove; PottingSoil selectedSoil = null; InteractableObject selectedInteractableObject = null; [Header("Messages to Player")] [Header("Harvesting Vegestable")] [SerializeField] string equipGloveMessage; [Header("Unequip Harvested Item")] [SerializeField] string unequipMessage; [Header("Harvesting Fruits")] public TextMeshProUGUI message; EquipmentData equipmentTool; void Start() { playerMove = transform.parent.GetComponent<PlayerMove>(); } void Update() { RaycastHit hit; Debug.DrawRay(transform.position, Vector3.down * 2, Color.red); if (Physics.Raycast(transform.position, Vector3.down, out hit, 2)) { OnInteractableHit(hit); } } void OnInteractableHit(RaycastHit hit) { Collider other = hit.collider; if(other.CompareTag("Pot")) { PottingSoil soilIndicator = other.GetComponent<PottingSoil>(); SelectPot(soilIndicator); return; } if (other.CompareTag("Harvestable")) { selectedInteractableObject = other.GetComponent<InteractableObject>(); return; } if(selectedInteractableObject != null) { selectedInteractableObject = null; } if(selectedSoil != null) { selectedSoil.Select(false); selectedSoil = null; } } void SelectPot(PottingSoil soilIndicator) { if(selectedSoil != null) { selectedSoil.Select(false); } selectedSoil = soilIndicator; soilIndicator.Select(true); } public void Interact() { ItemData toolSlot = NewInventoryManager.Instance.GetEquippedSlotItem(NewInventorySlot.InventoryType.Storage); EquipmentData equipmentTool = toolSlot as EquipmentData; //The Player must unequipped first the equipped Harvested before he can interact with the pots if (NewInventoryManager.Instance.SlotEquipped(NewInventorySlot.InventoryType.Harvest)) { Debug.Log("Hand is full with Harvested Crop"); message.text = unequipMessage; StartCoroutine(ClearMessageAfterDelay(2f)); return; } else { message.text = ""; } if (selectedSoil != null) { EquipmentData.ToolType toolType = equipmentTool.toolType; switch (toolType) { case EquipmentData.ToolType.HandTrowel: PlayerStats.UseStamina(10); selectedSoil.Interact(); return; case EquipmentData.ToolType.WateringCan: PlayerStats.UseStamina(10); selectedSoil.Interact(); return; } return; } } public void HarvestInteract() { /*ItemData playerToolSlot = NewInventoryManager.Instance.GetEquippedSlotItem(NewInventorySlot.InventoryType.Storage); EquipmentData equipmentTool = playerToolSlot as EquipmentData; //If Plalyer is not using the right tool for Harvesting if (equipmentTool == null || equipmentTool.toolType != EquipmentData.ToolType.HandGloves) { message.text = equipGloveMessage; StartCoroutine(ClearMessageAfterDelay(2f)); return; } else { message.text = ""; }*/ if(selectedInteractableObject != null) { selectedInteractableObject.PickUp(); } } public void HarvestKeep() { if (NewInventoryManager.Instance.SlotEquipped(NewInventorySlot.InventoryType.Harvest)) { NewInventoryManager.Instance.EquipToInventory(NewInventorySlot.InventoryType.Harvest); return; } } private IEnumerator ClearMessageAfterDelay(float delay) { yield return new WaitForSeconds(delay); message.text = ""; } }
January 6, 2025 at 11:56 am #17042::This somehow worked
public void Interact() { ItemData toolSlot = NewInventoryManager.Instance.GetEquippedSlotItem(NewInventorySlot.InventoryType.Storage); Debug.Log($"Equipped item: {toolSlot?.name ?? "None"}"); EquipmentData equipmentTool = toolSlot as EquipmentData; SeedData seedData = toolSlot as SeedData; // Check if the player has an equipped item in the Harvest slot if (NewInventoryManager.Instance.SlotEquipped(NewInventorySlot.InventoryType.Harvest)) { Debug.Log("Hand is full with Harvested Crop"); message.text = unequipMessage; StartCoroutine(ClearMessageAfterDelay(2f)); return; } if (selectedSoil != null) { if (seedData != null) { // If the player is holding a seed, plant it Debug.Log($"Planting seed: {seedData.name}"); PlayerStats.UseStamina(5); selectedSoil.Interact(); return; } if (equipmentTool != null) { EquipmentData.ToolType toolType = equipmentTool.toolType; switch (toolType) { case EquipmentData.ToolType.HandTrowel: PlayerStats.UseStamina(10); selectedSoil.Interact(); break; case EquipmentData.ToolType.WateringCan: PlayerStats.UseStamina(10); selectedSoil.Interact(); break; default: Debug.LogWarning("Tool not recognized for planting or watering."); message.text = "This tool can't be used here."; StartCoroutine(ClearMessageAfterDelay(2f)); break; } return; } Debug.LogWarning("No valid item equipped for interaction."); message.text = " "; StartCoroutine(ClearMessageAfterDelay(2f)); } }
January 6, 2025 at 12:11 pm #17043::status: Internal Server Error dateTime: 2025-01-06T04:11:08.731Z data: Program not found: 64386e21bb106b044ea34b78
January 6, 2025 at 2:10 pm #17046::This is a bug with part 29, follow part 30 and it will be resolved.
- 1 anonymous person
January 6, 2025 at 11:09 pm #17048 -
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.
Advertisement below: