- Home /
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 :)
Answer by robertbu · Nov 30, 2013 at 07:46 PM
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 $$anonymous$$an you are the best, it works perfectly now thanks to you :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613123126im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Snake Game problems - errors 2 Answers
"Object reference not set to an instance of an object" (Super simple) 1 Answer
Need Help with Shooting Script c# 5 Answers
Character moving forwards before pressing anything 0 Answers