I'm doing an android 2d platformer. In the Animator everything is set up. On applicaton start does everything right but when I click on the button the bool parameter does not change so my animation won't play backwards. But when I tick the bool parameter in the animator the animation plays right as it should. No console errors. Here is my script.

I was using this tutorial and from it I just needed the first part (the "Start game" animation part). I followed every step. Probably I'm missing something.

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.UI;
using UnityEngine;

public class UIManager : MonoBehaviour
{
    public Animator optionsButton;

    public void OpenSettings()
    {
        optionsButton.SetBool("isHidden", false);
    }
}

My goal is to play the animation backward when the option button is pressed and I want to change the bool parameter through a script.

1 Answers

0
Jozef Benko On

The problem was that the script was trying to change the bool on a canvas child element object. And there wasn't a bool. So I altered the existing script to get it. Worked perfectly.

public class UIManager : MonoBehaviour
{

    public Animator optionsButton;
    public bool hide;

  private void Start()
   {
       //to find the parent element - canvas - which has a bool
       optionsButton = GameObject.Find("MainMenu").GetComponent<Animator>();
   }

    public void OpenSettings()
    {
        hide = true;
        optionsButton.SetBool("AnimOut", hide);

        Debug.Log("I'm finaly working!");
    }

}