"a" conflicts with a declaration in a child block

Hey everyone, I’m quite new to Unity. I saw others posting the same issue, but I cannot relate their situation to mine: where does this code go wrong? The error is the following:

Assets/Scripts/Aiming.cs(46,28): error CS0135: `xmou’ conflicts with a declaration in a child block

and is related to the very last line of the following code:

public class Aiming : MonoBehaviour {

	float xmou;
	float zmou;

	void Update () {
		//1.calcolare posizione mouse ogni frame; 2.ruotare giocatore di x° rispetto al vettore (1,0,0)
		//1.trasforma posizione mouse da pixel ad angolo rispetto a vettore (1,0,0); 2.per ogni quadrante aggiungi o sottrai gradi
		//var pos = Camera.main.WorldToScreenPoint(transfor	m.position);
		float hei = Screen.height;
		float wid = Screen.width;
		float xmouabs = Input.mousePosition.x;
		float zmouabs = Input.mousePosition.z;
		

		if (xmouabs > wid/2){
		
			var xmou = xmouabs - wid/2;

			if (zmouabs > hei/2){
				var zmou = zmouabs - hei/2;}

			else{
				var zmou = zmouabs;}

		}

		else if (xmouabs < wid/2){
			
			var xmou = xmouabs;
			
			if (zmouabs > hei/2){
				var zmou = zmouabs - hei/2;}

			else{
				var zmou = zmouabs;}

		}


		Debug.Log (xmou.ToString ());

Take a closer look, you are declaring a variable named xmou at line 3: float xmou; and inside the Update() at line 18 you declare another variable with the same name var xmou.

The first xmou has class scope and will exist everywhere inside your class, including inside any method scope, this is why you can’t declare a new one. To get more information about this search for C# Scope .

You don’t need to write var or anything in front of variables when you assign them, only when you declare them.

xmou = xmouabs - wid / 2;
zmou = zmouabs - hei/2;

And so on.