Why am I getting an error here?

I know this is super obvious and I’m kind of embarrassed to ask this but…

Why am I getting an error here? Here is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickUp : MonoBehaviour {

    public bool isHolding;
    public Transform theDest;

    void Input.GetKeyDown(KeyCode.E) && isHolding = false //from here down is where my errors are
    {
        GetComponent<Rigidbody>().useGravity = false;
        this.transform.position.theDest.position;
        this.transform.parent = GameObject.Find("Destination").transform;
    }

}

You are half-writing a function header (such as void Update()) and (it looks like) half writing an if statement (if (blah) ).

I do this a lot when I have had too much coffee. My approach is to take my hands away from the keyboard and breathe deeply several times, then resume.

lol, I haven’t had too much coffee I just don’t know what the heck I’m doing. I’m following a tutorial for a pickup script but he is making it so when you click, you pick it up. but I want to make it so when I press e, I pick it up. please tell me how i do that?

Taking a wild guess what you meant to write:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickUp : MonoBehaviour {

    public bool isHolding;
    public Transform theDest;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E) && isHolding == false) //from here down is where my errors are
        {
            GetComponent<Rigidbody>().useGravity = false;
            this.transform.position.theDest.position;
            this.transform.parent = GameObject.Find("Destination").transform;
        }
    }

}

So I just added the Update declaration, turned what is probably an “if” statement actually into one, and turned your assignment of isHolding into a comparison.

Though this code is a terrible idea. You should try to avoid GetComponent in Update when possible, and you should never put GameObject.Find in Update. For performance reasons. Actually you should never use GameObject.Find at all, as there is always a better option. But there are endless discussions on that topic if you’re interested.

Ok. I’ll fix it. Why should I avoid GetComponent in Update and never put GameObject.Find in update?

Just put in your code, but I just noticed that I have some errors.

5818834--616477--SomeErrors.png

Uncle Joe didn’t write that. It was from OP’s original code line 13. I guess it should be:

this.transform.position = theDest.position;

Every single character, including punctuation and capitalization, is critical to get right when programming. It’s not like sending text messages.

1 Like

Yeah. I had the errors before I put the code in. But thank you, the errors are gone now.

Yeah I don’t have VS on this computer and didn’t really check any line of code that I wasn’t actually editing :stuck_out_tongue: I mostly just demonstrated what Kurt already suggested.

Good luck with your Unity journey :slight_smile:

You might want to consider a general C# tutorial, so you understand classes, methods, etc, so can spot these issues yourself immediately. These weren’t actually Unity issues, but basic C# syntax issues. A Unity tutorial would generally not cover basic C# syntax, since it is an industry standard language created by Microsoft not Unity.

1 Like

WHAT. There back. Here’s a screenshot.

I watched a c# tutorial series by blackthornprod, thats how I know anything at all

I think you better work back through some C# basics. You’re conflating classes and function headers and block conditional controls at a minimum, not to mention getting all kinds of syntax twisted up.

2 Likes