Search Unity

(Input.GetMouseButtonDown(0)) Not Working - Need Help

Discussion in 'Animation' started by Psylova, Feb 7, 2019.

  1. Psylova

    Psylova

    Joined:
    May 5, 2016
    Posts:
    7
    Hey everyone. I am very new to Unity and am an absolute beginner when it comes to programming. I am following a tutorial at the moment by a guy called Brackeys on how to fade in and out of scenes. At a certain point in the video, he tells us to write this code.

    void Update()
    {
    if (Input.GetMouseButton(0))
    {
    FadeToLevel(1);
    Debug.Log("Click!");
    }
    }

    I added the Debug.Log on my own but the rest is his. It's supposed to make it so that when I press the left key on the mouse, it plays an animation, but it's not doing anything. I added the Debug.Log so that I would know whether or not it knew I was pressing it, and nothing happened. It's not sensing that I'm pressing the button. I've tried everything I can think of and I don't know what to do. Here is the video:



    It's at about 8 minutes in.

    If anyone can give me some advice it would be greatly appreciated!

    FULL CODE:

    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class LevelChanger : MonoBehaviour {

    public Animator animator;

    private int levelToLoad;

    // Update is called once per frame
    void Update()
    {
    if (Input.GetMouseButton(0))
    {
    FadeToLevel(1);
    Debug.Log("Click!");
    }
    }

    public void FadeToLevel(int levelIndex)
    {
    levelToLoad = levelIndex;
    animator.SetTrigger("FadeOut");
    }

    public void OnFadeComplete ()
    {
    SceneManager.LoadScene(levelToLoad);
    }
    }
     
  2. kural_varman

    kural_varman

    Joined:
    Jan 6, 2023
    Posts:
    2
    Sorry, for late answer i have same problem (1/4/2023), below answer is what i found searching internet and wanted to post it for u .

    from Stackoverflow website-
    After hours spent on this exact problem, I realized that the problem comes from Windows, not Unity. On any modern Windows version, the touchpad buttons are deactivated if any key is pressed.

    To solve the issue, simply go to Touchpad Settings, and set it to sensitive.

    for more details the link is here to the answer i wrote it-
    https://stackoverflow.com/questions/37764844/unity-c-input-getmousebutton-not-calling