Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

The Fix To CS0103

Discussion in 'Scripting' started by emoney101skeleton, Jun 27, 2020.

  1. emoney101skeleton

    emoney101skeleton

    Joined:
    Jun 7, 2020
    Posts:
    8
    So Working On This Code and I Don't Know If I'm Not Thinking Well But I Got This Error In This Code
    The name 'Axis' does not exist in the current context

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMove : MonoBehaviour
    {
    private CharacterController charController;

    public float movement_Speed = 3f;
    public float gravity = 9.8f;
    public float rotation_Speed = 0.15f;
    public float rotateDegreesPerSecond = 180f;

    void Awake ()
    {
    charController = GetComponent<CharacterController> ();
    }

    // Update is called once per frame
    void Update()
    {
    Move();
    Rotate();
    }

    void Move() {

    if(Input.GetAxis(Axis.VERTICAL_AXIS) > 0) {

    Vector3 moveDirection = transform.forward;
    moveDirection.y -= gravity * Time.deltaTime;

    charController.Move(moveDirection * movement_Speed * Time.deltaTime);

    } else if(Input.GetAxis(Axis.VERTICAL_AXIS) < 0)
    {

    Vector3 moveDirection = -transform.forward;
    moveDirection.y -= gravity * Time.deltaTime;

    charController.Move(moveDirection * movement_Speed * Time.deltaTime);

    }

    } //move

    void Rotate()
    {

    Vector3 rotation_Direction = Vector3.zero;

    if(Input.GetAxis(Axis.HORIZONTAL_AXIS) < 0)
    {
    rotation_Direction = transform.TransformDirection(Vector3.left);

    }

    if (Input.GetAxis(Axis.HORIZONTAL_AXIS) > 0)
    {
    rotation_Direction = transform.TransformDirection(Vector3.right);
    }

    } // rotate[/code]

    Once again Their Might Be a Easy Fix To This
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,021
    Please use code tags, and always indicate which line the error occurs on.

    Where are
    Axis.VERTICAL_AXIS
    and
    Axis.HORIZONTAL_AXIS
    coming from? Are those something you defined? As far as I can tell they're not part of UnityEngine.
     
  3. emoney101skeleton

    emoney101skeleton

    Joined:
    Jun 7, 2020
    Posts:
    8
    There Not? I been using a video tutorial
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,021
    Input.GetAxis takes a string as an argument, which should be the name of the axis as defined in the input manager.

    Defining your own constants so that you don't need to litter string literals throughout your code isn't a bad idea. That might look something like:
    Code (CSharp):
    1. public static class Axis {
    2.     public const string HORIZONTAL_AXIS = "Horizontal";
    3.     public const string VERTICAL_AXIS = "Vertical";
    4. }
    But to the best of my knowledge Unity does not do it for you (you can set the names of the axes to anything you want, although "Horizontal" and "Vertical" are both defaults). I don't see those in the online scripting API, and the fact that you got that compiler error certainly suggests that they aren't in there.

    It's possible the tutorial writer defined those constants themself, and either you missed that part of the tutorial or they forgot to cover it.
     
unityunity