- Home /
Even more errors
Hi again i am asking for some help i have a ton of errors! ERRORS:
error CS0103: The name
movementspeed' does not exist in the current context 2. error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3.error CS0103: The name
movementspeed' does not exist in the current context
4.error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
CODE:
using UnityEngine;
using System.Collections;
public class FirstPersonController : MonoBehaviour {
public float movementSpeed = 5.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float rotLeftRight = Input.GetAxis ("Mouse X");
transform.Rotate(0, rotLeftRight, 0);
float forwardspeed = Input.GetAxis ("Vertical") = movementspeed;
float sideSpeed = Input.GetAxis ("Horizontal") = movementspeed;
Vector3 speed = new Vector3 ( sideSpeed, 0, forwardspeed );
CharacterController cc = GetComponent<CharacterController> ();
cc.SimpleMove( speed );
}
}
Answer by robertbu · Mar 02, 2014 at 08:00 PM
In fixing errors, it is easiest/best to fix the top error and then return to Unity and allow the file to recompile. Fixing one error may remove a dozen errors in the Console, or it might expose a dozen. Typically only the first error or two have meaning. Beyond that it is just the compiler getting confused. In your case, you only have two errors. You've misspelled 'movementspeed' and are using '=' instead of '*' on lines 20 and 21. The two lines should be:
float forwardspeed = Input.GetAxis ("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis ("Horizontal") * movementSpeed;
Fix those two lines, and I believe your script will compile. And don't get overwhelmed by errors. Just take them one at a time from the top.
thanks! That solved all my issues but i have another where it says this, "The referenced script on this Behaviour is missing!" can you shed some light on the situation?
(Btw, just started C#, literally yersterday)
You need to give context for this new problem. Script, line number, etc. Open it as a new question unless it relates directly to the script above.