'GameObject' is a type, which is not valid in the given context

so I am making a script for the bullets to helps one of my sprites shoot bullets but it keeps telling me that game object is a type and its getting annoying since I have no clue whats wrong.

Heres the script for my bullet but I haven’t got a clue whats wrong since I’m new to this

void Start()
    rb = GetComponent<Rigidbody2D> ();
    target = GameObject.FindObjectOfType<Player>();
    moveDirection = (target.transform.position - transform.position).normalized * moveSpeed;
    rb.velocity = new Vector2 (moveDirection.x, moveDirection.y);
    Destroy (GameObject, 3f);

void OnTriggerEnter2D (Collider2D col)
    if (col.gameObject.name.Equals ("Player")) {
        Debug.Log ("Hit!");
        Destroy (GameObject);


Hello, its Destroy(gameObject);

Uppercase GameObject is the class, but you need lowercase gameObject, which is a property of the Component class and returns you the attached gameObject.

to be exact you are trying to “Destroy” a class named “GameObject” what you want is to destroy a reference to a game object, if this script is attached to the bullet directly you can just do this:

Destroy (this.gameObject, 3f);


Destroy (gameObject, 3f);

which I’m sure that’s what you meant instead of the capitalized version of gameObject,

easy to mistake.

Thanks for that I was wondering why it wasnt working so thank you for the information