Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

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

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

  1. psylova

    psylova

    Joined:
    May 5, 2016
    Posts:
    1
    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);
    }
    }