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
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.
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): public static class Axis { public const string HORIZONTAL_AXIS = "Horizontal"; public const string VERTICAL_AXIS = "Vertical"; } 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.