CS1525 "Public" Error on Float

Hello!

I am playing around with the start of a C# script that will change a UI image based on a float that is changed based on a user input. I havn’t played with Unity in a very long time, last time I used it was Unity 2 and now in Unity 4 they have changed the API.

Why do my public floats get the CS1525 Error “Unexpected symbol `public’”

Here’s the code I have right now:

using UnityEngine;
using System.Collections;

public class Move1 : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
	{

		//Variables
		public float thrustersMax = 100f;       //Errors are concerning all of
		public float thrustersMin = 0f;         //the following float variables.
		public float thrustersCur = 0f;
		public float thrustersInc = 8f;

		public Transform ThrustersUI;

		//Raise Thrusters
		if (Input.GetKey(KeyCode.KeypadPlus)) {
			thrustersCur += thrustersInc;
		}

		//Lower Thrusters
		if (Input.GetKey (KeyCode.KeypadMinus)) {
			thrustersCur -= thrustersInc;
		}
	}
}

I have not added the code for changing the image in the UI yet. All I am trying to do now is when the user presses Numpad + or - the “current” value will change by an increment. My floats do not like me.

Whats wrong with my floats?

Thanks for help, it is appreciated!

Definition from MSDN about the scope of variables :

The scope of a variable, sometimes referred to as accessibility of a variable, refers to where the variable can be read from and/or written to, and the variable’s lifetime, or how long it stays in memory.

Source : Variable and Method Scope in Microsoft .NET | Microsoft Learn

Here, you are trying to add an Access Modifier to variables defined inside a method which doesn’t make sense.

If you want your floats to be accessible from any other class, then you should define them as attributes of your Move1 class and not somewhere else.
If you want your floats to be accessed only inside the method, then the Access Modifiers are not useful here and they even must not be added.

Please, learn how to code properly before trying to make games…