Search Unity

input on buttons

Discussion in 'Editor & General Support' started by BadriRusadze, Feb 16, 2020.

  1. BadriRusadze

    BadriRusadze

    Joined:
    May 17, 2019
    Posts:
    27
    Hello, someome please help, or i throw my pc through window :D
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;

    5. public class Controleri : MonoBehaviour
    6. {
    7. public void SpaceKnopka()
    8. {
    9. Input.GetKeyDown(KeyCode.Space);
    10. }
    11. }
    i made this code, and i set SpaceKnopka to button onclick, so button had same function as Space on keyboard.
    i also tried Input.GetKey(KeyCode.Space); , neither works.

    im talking about 2D game kit. i want to add mobile controls. please someone godsend help me , im searching internet for 4 days already how to add inputs on UI buttons.

    Code (CSharp):
    1. Code (CSharp):
      1. using System.Collections;
      2. [*]using System.Collections.Generic;
      3. [*]using UnityEngine;
      4. [*]using UnityEngine.UI;
      5. [*]
      6.  
      7. [*]public class Controleri : MonoBehaviour
      8. [*]{
      9. [*]   public void SpaceKnopka()
      10. [*]    {
      11. [*]        Debug.Log(Input.GetKeyDown(KeyCode.Space));
      12. [*]    }
      13. [*]}
      14. [/LIST]
      15. This returns FALSE.