Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Getting data from other component

Hello Guys!

I've followed the brackeys series on how to make an RPG, after finishing the series i continued working on the game. Now i wanted to implement a lifeskilling script for woodcutting, mining etc.

I've already made it so that when i have equiped an axe, my woodcutting void within the lifeskilling script activates.

now i want to continue with making an if statement that checks if the Focus of player movement isn't null and if it's focused on the interactable object with tag choppable tree.

How would i go about this?

Best Answer

  • Sl0thSl0th Member
    Accepted Answer

    Tree is a GameObject, focus is an Interactable. You can't just compare those two as you do in the if statement (also, you forgot a double =). Your Tree should be of type Interactable. So when you find your tree in the start method, you need to say

    Tree = GameObject.FindWithTag("ChoppableTree").GetComponent<Interactable>();

Answers

  • KefkeuhsKefkeuhs Member
    edited September 9

    UPDATE: I finally managed to check if the value != null. Now when i try to check if the interactable gameobject has the tag "ChoppableTree" it gives me this error:

     error CS0029: Cannot implicitly convert type 'UnityEngine.GameObject' to 'Interactable'

    the code i'm uing for checking this is:


    public GameObject Player;

    PlayerMovement playermovement;

    GameObject Weapon;

    GameObject Tree;


    private Interactable focus;


    void Start()

    {

    playermovement = Player.GetComponent<PlayerMovement>();

    Tree = GameObject.FindWithTag("ChoppableTree");

    }

    void Woodcutting () 

    {


    if (playermovement.focus != null)

    {

    if (playermovement.focus = Tree)

    {

    Debug.Log("I see something");

    }

    }

    else 

    }

    If you need more information that could help you solve my problem, please feel free to ask

  • @Sl0th I feel so stupid now, i was searching for so long after this. Thank you so much, it worked perfectly!

  • No problem, little things like that can drive one crazy! You'll get the hang of recognising those errors.

Sign In or Register to comment.