Forum begins after the advertisement:


[Part 7] Autocollect items

Home Forums Video Game Tutorial Series Creating a Farming RPG in Unity [Part 7] Autocollect items

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14732
    Jonathan Teo
    Moderator

    If you want it to just auto-collect the items if the player is near them instead of having to click, simply add a boolean in InteractableObject autoCollect. Then in the OnInteractableHit add a check for whether the autoCollect is checked, if so, run the pickup function. It will look something like this:

    if(other.tag == “Item”)
    {
    //Set the interactable to the currently selected interactable
    selectedInteractable = other.GetComponent();
    if(selectedInteractable.autoCollect)selectedInteractable.Pickup();
    return;
    }

    #14780
    Fathurrachman
    Participant

    hi, thank you for posting this tutorial. i tried to applied on the script on the OnInteractableHit method like this :

    if (other.tag == "Item")
    {
        selectedInteractable = other.GetComponent<InteractableObject>();
    
        if (selectedInteractable.autoCollect)
        {
            selectedInteractable.Pickup();
        }
        else
        {
            selectedInteractable.OnHover();
        }
        return;
    }

    but the item (e.g. egg or milk) isn’t auto collect, i have to tap the item to collect, can you help me?

    Thanks

    #14785
    Jonathan Teo
    Moderator

    Hi Fathurrachman,
    Check if the item has autoCollect checked in the prefab. If it is checked, does the OnHover behaviour run anyway?

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: