weird error happening with variable

in my code I was writing down a private in variable and when I put it in I got two errors one saying that top level statements must precede namespace and type declarations. And the other saying The modifier public is not valid for this item. I put my code in the picture, what do I need to do?

Photographs of code are not a thing.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

Why is the int in a block?

Go look at any C# class example.

You are killing your entire script at the outset, with the closing bracket after “private int”. ( } ) And then the opening bracket after that… ( { ) is not doing anything. The rest of the code after is being ignored.

Kurt is correct.

Look at anyone else’s C# script, and see how the Class area at the top looks. You need to be very mindful of using { and }. Often times, you might be killing your functions because of too many }, or missing one.

whenever I delete the brackets around the int I get errors that say } excpected

That’s not how coding works… you may wish to start with some basic C# tutorials.

You do need one opening bracket, right below your CLASS title. and the closing bracket for that opening bracket… does not come until the VERY END of your script.

public class YourScript : MonoBehaviour
{

// float
// int
// bool
// opening declarations



void Awake()
{
// awake stuff here
}

void Start()
{
//start stuff here
}

void Function()
{
//your new function stuff here
}

//one final }

}

I laughed when I read this but still…
here’s a photograph of that code (in visual scripting) ^.^

8456633--1122299--lol.PNG

Then allow me to amend my statement:

Photographs of code are not a thing in the Scripting forum.

You may however get more traction with your photographs over here:

https://forum.unity.com/forums/visual-scripting.537/

1 Like