Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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);
    }
    }