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
  3. Dismiss Notice

Cant get input.getbuttondown to work correctly

Discussion in 'Scripting' started by bschutte, Jun 5, 2016.

Thread Status:
Not open for further replies.
  1. bschutte

    bschutte

    Joined:
    Jun 5, 2016
    Posts:
    6
    Hello! I'm very new to scripting and I'm currently trying to learn inputs. I've been watching various videos but have been stuck on getting an input to work. Here's the line of code that won't work:

    void Update ()
    {
    if (Input.GetButtonDown ("TO"))
    Debug.Log ("Test!");
    }

    That's basically all the script. I left out the class and the first couple lines at the beginning, and to me it feels as thought this script should work fine. I've gone into Edit and changed the Input settings for TO, and I have bound it to r, but it wouldn't read out in the console. So I tried starting a new project and now I have a compiler error "Input does not contain a definition for GetButtonDown".

    I have tried every solution I can think of! I hope you guys can help me sort this out!

    PS If there are any awesome scripting videos I should check out, lemme know!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    don't do this, you're assuming the problem is in the snippet you've provided and not elsewhere in the script, whilst at the same time saying you have no idea why its not working. Give us the entire script.... and use code tags http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  3. bschutte

    bschutte

    Joined:
    Jun 5, 2016
    Posts:
    6
    Okay my bad! I wasn't aware of the tag! I will include everything in my script, including my double slashes (I was using them for notes, so feel free to comment on them and make adjustments if I need to).
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System;
    5.  
    6. public class Input : MonoBehaviour {
    7.  
    8.     //this function will use the method GetKey & GetButton
    9.     //which will check if the player has pressed the key you detail
    10.  
    11.     //once they do, they will perfrom the action you specify
    12.  
    13.     //GetKey will search for a specific key and that key only
    14.  
    15.     //GetButton will search for a key that the user can specify in the console
    16.  
    17.     // Update is called once per frame
    18.  
    19.     void Update ()
    20.     {
    21.         if (Input.GetButtonDown ("TB"))
    22.             Debug.Log ("Have a party!");
    23.     }
    24.  
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The error about the non-existent method occurs because you've named your own class "Input".
    The Input class that you want to access belongs to the UnityEngine namespace, however, as your code belongs to your own class with that name, it will refer to that instead of using the UnityEngine.Input class.

    Easiest solution: rename your class.
     
  5. bschutte

    bschutte

    Joined:
    Jun 5, 2016
    Posts:
    6
    Thanks for your help!
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    No problem.

    So does it still not recognize the input?
     
  7. bschutte

    bschutte

    Joined:
    Jun 5, 2016
    Posts:
    6
    No your solution helped me and it now recognizes the input :)
     
    Suddoha likes this.
  8. Matthew0017

    Matthew0017

    Joined:
    Apr 14, 2020
    Posts:
    1
    I am having the same issue
     

    Attached Files:

  9. CharcoolEpic

    CharcoolEpic

    Joined:
    Aug 21, 2020
    Posts:
    2
    So do I, the error says 'Input' does not contain a definition for 'GetDownButton'.


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

    public class PlayerMovement : MonoBehaviour
    {

    public float speed;
    public float jump;

    private float move;
    private Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
    move = Input.GetAxisRaw("Horizontal");

    rb.velocity = new Vector2(move * speed, rb.velocity.y);
    if (Input.GetDownButton("Jump"))
    {
    rb.AddForce(new Vector2(rb.velocity.x, jump));
    }
    }
    }
     
  10. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    It's GetButtonDown, not GetDownButton.

    Please always use code tags and please do not post in old threads. It's always better to start a new one.
     
  11. juanjoguerrero2175

    juanjoguerrero2175

    Joined:
    Apr 17, 2021
    Posts:
    1
    My problem was that i didnt put a mayus, im sooooooooooooo hapyyy}
     
Thread Status:
Not open for further replies.