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

Input.GetButtonDown not working

Discussion in 'Scripting' started by techbliz, Dec 8, 2020.

  1. techbliz

    techbliz

    Joined:
    Dec 7, 2020
    Posts:
    3
    For some reason i followed everything this guy said from his youtube
    (2) 2D Movement in Unity (Tutorial) - YouTube
    see 14:28 for the full layout
    1 thing i noticed his input tags are orange and mine is white which scares me, also i can move left and right but when i try space bar it doesnt work, also at he got his Debug.Log(Input.GetAxisRaw("Horizontal")); to work and i followed along perfectly but still i didnt see a single console in my game.


    this is me failing to jump with spacebar
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class playermovement : MonoBehaviour{

    public CharacterController2D controller;

    public float RunSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;

    // Update is called once per frame
    void Update()
    {
    horizontalMove = Input.GetAxisRaw("Horizontal") * RunSpeed;
    if (Input.GetButtonDown("Jump"))
    {
    jump = true;
    }
    }




    void FixedUpdate()
    {
    //Move character
    controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
    jump = false;
    }

    }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run?
    - what are the values of the variables involved? Are they initialized?

    Knowing this information will help you reason about the behavior you are seeing.
     
  3. techbliz

    techbliz

    Joined:
    Dec 7, 2020
    Posts:
    3
    Only walking lleft and right is working. Im 100% newbie
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    None of us are going to go do the tutorial, and assuming the tutorial works, I recommend you go back and check out what steps you might have missed regarding jumping. I see code in there for jump, so that is why I recommend you put Debug.Log() statements in to see if it is being detected, passed in, etc.
     
  5. techbliz

    techbliz

    Joined:
    Dec 7, 2020
    Posts:
    3
    Ok. I downloaded his project but and it worked. He inseted the entire player folder in the game. Firstly i dont know how to do that cuz when i drag the folder in, it shows the stop symbol meaning i cant. But i got through