Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development How to Make a Video Game Player Input and Cameras Rotate the Player Towards the Target

Error CS0103: The name " " does not in exist in the current context. This happens in several places.

In my PlayerMovement.cs I get this error with MonoBehaviour, Animator, playerAnimator, Vector3, Rigidbody, and Qauternion. Here is a copy of my file:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    private Animator playerAnimator;
    private float moveHorizontal;
    private float moveVertical;
    private Vector3 movement;
    private float turningSpeed = 20f;
    private Rigidbody playerRigidbody;

    // Use this for initialization
    void Start () {

        // Gather components from the play GameObject
        playerAnimator = GetComponent<Animator> ();
        playerRigidbody = GetComponent<Rigidbody> ();

    }

    // Update is called once per frame
    void Update () {

        // Gather input from the keyboard
        moveHorizontal = Input.GetAxisRaw ("Horizontal");
        moveVertical = Input.GetAxisRaw ("Vertical");

        movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    }

    void FixedUpdate () {

        // If the player's movement vector does not equal zero...
        if (movement != Vector3.zero) {

            // ...then create a target rotation based on the movement vecor...
            Quaternion targetRotation = Quaternion.LookRotation(movement, Vector3.up);

            // ...and create another rotation that moves from the current roatation to the target rotation...
            Quaternion newRotation = Qauternion.Lerp (playerRigidbody.rotation, targetRotation, turningSpeed * Time.deltaTime);

            // ...and change the player's rotation to thenew incremental rotation...
            playRotation.MoveRotation(newRotation);

            // ...then play the animation.
            playerAnimator.SetFloat ("Speed", 3f);
        } else {
            //Otherwise don't play the animation
            playerAnimator.SetFloat ("Speed", 0f);
        }

    }

}

Any help would be greatly appreciated. Thank you!

Alan Mattan贸
Alan Mattan贸
Courses Plus Student 12,188 Points

In the error console message gives you the line number where is the error.

Thank you, Alan! A closer look and I was able to figure out what (and where) the problems were! It also became obvious that the errors were showing in red. Such a great text editor! Thanks again.

2 Answers

Alan Mattan贸
PLUS
Alan Mattan贸
Courses Plus Student 12,188 Points

Go to the Console by pressing Ctrl Shift "C" or in the top menu: Windows -> Console . The Console will show you the Error message with the file location "Assets/Path/FileName.cs" and the line number, where is the error. In your case is can be 103 then there is a coma and the position. If you double click the error message in the console, Unity will try to open Mono putting the cursor at the same position where is the error. It can be shown in red. The error can be not in the same line, for example if we forget to close a ; or }. In this case look line above the error. The console will show you more than one error probably as consequence of the first one. So if you fix the first error, the other errors messages probably will disappear.

Great to know! Thanks again Alan! :)