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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question (3D) Input.GetAxis("Horizontal"); not being accepted

Discussion in 'Scripting' started by DavidHenson, Jun 16, 2022.

  1. DavidHenson

    DavidHenson

    Joined:
    May 3, 2022
    Posts:
    4
    I'm currently following a tutorial to try and learn unity 3D character movement and the code for the movement isn't working, returning "unexpected character """" in the console around my Input.GetAxis("Horizontal"); and Input.GetAxis("Vertical");
    Here's my code:
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class NewBehaviourScript : MonoBehaviour
    7. {
    8.    public CharacterController characterController;
    9.    public float speed = 6;
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.    Move();      
    15.     }
    16.  
    17.    private void Move()
    18.    {
    19.    float horizontalMove = Input.GetAxis(“Horizontal”);
    20.    float verticalMove = Input.GetAxis(“Vertical”);
    21.  
    22.    Vector3 move = transform.forward * verticalMove + transform.right * horizontalMove;
    23.    characterController.Move(speed * Time.deltaTime * move);
    24.    }
    25. }
    26.  
    I've verified that these are the same names used in my input manager and I've been searching for a couple hours and haven't found a way to fix this, if there's anything apparently obvious with my code or a way to fix it, I'd appreciate the help.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,006
    The quotation marks in your code copy look a little different than normal ones:
    Code (CSharp):
    1. "Horizontal"
    Something up with your keyboard perhaps? Looks like it's the 'modified double apostrophe' according to character map.
     
    Bunny83 likes this.
  3. DavidHenson

    DavidHenson

    Joined:
    May 3, 2022
    Posts:
    4
    This did solve my problem, thank you!
    That's very weird, I'm writing in MacOS's TextEdit, and it seems to convert surrounding "" into “”.
    I was able to disable this under Edit/Substitutions/Smart Quotes disabled.
     
    Bunny83 and spiney199 like this.
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,571
    Uhhgg, :) You really should use an actual IDE. It also helps you with syntax highlighting, code suggestions and syntax errors. Visual Studio does also exist for MacOS. It probably has the most features. Though any other kind of IDE would be better than a rtf editor to write letters ^^.
     
    DavidHenson likes this.