Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question guys are giving error the name "z" does not exist in the current context CS0103

Discussion in 'Scripting' started by italocostadossantos4, May 27, 2021.

  1. italocostadossantos4

    italocostadossantos4

    Joined:
    May 27, 2021
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {

    public CharacterController controller;


    public float speed = 12f;
    // Start is called before the first frame update


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

    float x = Input.GetAxis("horizontal");
    float y= Input.GetAxis("vertical");

    Vector3 move = transform.right * x + transform.forward * z;


    controller.Move(move * speed * Time.deltaTime);



    }
    }
     

    Attached Files:

  2. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    272
    Where is z defined in your code? I see usage, where is definition?
     
  3. BuyAnElefant

    BuyAnElefant

    Joined:
    Mar 9, 2021
    Posts:
    8
    You've created x and y variables, but never created z
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The important parts of an error message are:
    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/