backgroundCleaner.cs(5, 47): error CS1514: } expected

HI everyone, getting the following error code ‘backgroundCleaner.cs(5, 47): error CS1514: } expected site:forum.unity.com’

from the following script:

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

public class backgroundCleaner : MonoBehaviour

     private void OnTriggerEnter2D(Collider2D collision)

{
    if(collision.tag == "Background")
    {
        float widthOfObject = ((BoxCollider2D)collision).size.x;

        Vector3 position = collision.transform.position;

        position.x += widthOfObject * 1.99f;

        collision.transform.position = position;
    }

}

Can anybody see what I am doing wrong please? I am trying to make a screen cleaner for a side scrolling game. I want to put my backgrounds into a pool to recycle them (learning about preserving memory currently). Any help would be really appreciated. Cheers in advance guys & gals :smile:

You need another set of curly braces { } for the class as a whole, starting on line 6 and ending on line 22. (You should also consider standardizing your indentation, which won’t affect what the code actually does but makes it easier to read and understand.)

1 Like

Thanks dude! Was literally just trying to find this post to say I need to stop posting on here out of frustration, I saw it too about 3-4 mins after posting (what a donut I am). Thank you though for your speedy response, I literallt just posted :smile: all the best. You are a diamond!