Why do these errors keep showing up with C#? Im a beginner with coding

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public float movementspeed = 5.0f; 
public float MouseSensitivity = 5.0f;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	//Movement with mouse
	transform.Rotate(0.0f ,rotleftright,0.0f);
	float rotleftright = Input.GetAxis ("Mouse")*MouseSensitivity;

	// This is all movement coding
float ForwardSpeed = Input.GetAxis("Vertical")* movementspeed;
float sidespeed = Input.GetAxis("Horizontal")* movementspeed;
	Vector3 speed = new Vector3 (ForwardSpeed, 0.0f, sidespeed);
CharacterController cc = GetComponent<CharacterController>();

	speed = transform.rotation * speed;

	cc.SimpleMove( speed );
}

}

These errors pop up
-Assets/Scripts/NewBehaviourScript.cs(16,40): error CS0841: A local variable `rotleftright’ cannot be used before it is declared

-Assets/Scripts/NewBehaviourScript.cs(16,27): error CS1502: The best overloaded method match for `UnityEngine.Transform.Rotate(float, float, float)’ has some invalid arguments

-Assets/Scripts/NewBehaviourScript.cs(16,27): error CS1503: Argument #2' cannot convert object’ expression to type `float’

Could someone please help me understand the problems in basic terms thank you :slight_smile:

1 Answer

1

You use ‘rotleftright’ on line 11 in the Rotate() call, but you don’t declare and initialize the variable until line 12. Reverse the order of these two lines to get rid of the error.

Thanks Man you are the best, it works perfectly now thanks to you :)