string cannot be accesed with an instance refference.

hi its me again
im still working on my game and I’m getting 2 errors which are in both scripts.
the first one is in the title and the second one is (script) doesn’t have a Definition for Tag
any help?

    void Update()
    {
        Hand.gameObject.Find("Hand");
        if (this.transform.parent == Hand.transform.parent)
        {
            cardBack = false;
        }
        staticCardBack = cardBack;

        if(this.Tag = "Clone")
        {
            displayCard[0] = PlayerDeck.staticDeck[numberOfCardInDeck - 1];
            numberOfCardInDeck -= 1;
            PlayerDeck.deckSize -= 1;
            cardBack = false;
            this.tag = "Untagged";
        }
    }

It helps to pose the full errors so we know what line they’re on (as well as the full script, so we can match up those lines).

Though for your second error this in monobehaviour scripts refers to a component. Component’s don’t have tags, the game object they’re on does. Hence, you want this.gameObject.tag.

Does your IDE not have working autofill suggestions?

1 Like

I see three main issues with your post. First of all you said you get error but you haven’t posted the full error and haven’t told us which line those errors appear. The compiler tells you the filename as well as the line number and even the column number in which the error occurred. You can copy the error message from Unity’s console window, at least from the bottom half where the details are shown.

The next issue is this line

which literally does nothing. Because you have this line that does nothing it directly leads me to the third issue which is that we don’t know what “Hand” actually is. I suspect that this is the actual issue here. Unless “Hand” is either a gameobject or a component the aforementioned line as well as the following if statement would throw an error. Since your title said something about “string”, I would further assume that this “Hand” variable might be a string? If that’s the case, the code just makes no sense and we can’t really make any sane assumptions without more details.

If that’s not the issue, we also don’t know what PlayerDeck is. So there are way too many unknowns in that post which makes it impossible to solve your issue. You really need to include more details.

Actually components also have a tag property which directly maps to the gameobject’s tag property. It kinda makes sense they added this shortcut. The weirdest and most pointless shortcut is the GameObject.gameObject property. It simply returns itself…

1 Like