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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17041
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    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 = "";
        }
    }
    #17042
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    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));
        }
    }
    #17043
    Tarha Apustaja
    Level 3
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    status: Internal Server Error dateTime: 2025-01-06T04:11:08.731Z data: Program not found: 64386e21bb106b044ea34b78

    #17046
    Jonathan Teo
    Level 18
    Moderator
    Helpful?
    Up
    1
    ::

    This is a bug with part 29, follow part 30 and it will be resolved.

      1 anonymous person
    has upvoted this post.
    #17048
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    1
    ::

    Thank you

      1 anonymous person
    has upvoted this post.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: