Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Its suppost to take input form Keyboard but this script does NOTHING!

Discussion in 'Getting Started' started by alexgulin, Jan 30, 2020.

  1. alexgulin

    alexgulin

    Joined:
    Jan 29, 2020
    Posts:
    1
    transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(Mathf.Clamp(gameObject.transform.position.x + moveHorizontal, -2.5f, 2.5f), gameObject.transform.position.y, gameObject.transform.position.z), directionalSpeed * Time.deltaTime);

    Its suppost to take input form Keyboard but this script does NOTHING!

    There is no errors, no warnings, no suggestions in Visual Studio and Unity but when I play and press the buttons - it simply does nothing - no any signs from input. WHY???

    Please HELP!
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome!

    First, let me point you to the post about using code tags. This will format your code so that it's easier for the rest of us to read.

    Looking at your code, I don't see where you're using any input at all. I'm guessing you got this bit of code from a tutorial. It seems you may have missed copying something before this piece that actually collects the keyboard input and processes/stores it (in that moveHorizontal variable, perhaps?) before this code is supposed to be executed.

    Could you share the tutorial you're working with, and the full contents of your script file?
     
    JoeStrout, Bill_Martini and Ryiah like this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Also remember that even if your script is 100% correct, just having a script in your project does nothing. You have to actually attach the script to an active object in your scene hierarchy before it can have any effect.
     
    Schneider21 likes this.