How to disable animation after SetActive(true) in Unity?

clock icon

asked 10 months ago Asked

message

0 Answers

eye

1 Views

 have an animated UI obj (A button) that plays the animation (is switching sprites, between sprite1 and sprite2) after a certain condition, after the button is pressed the sprite of the button changes to sprite3 but when I'm setting active the button to false SetActive(false) and reenable to SetActive(true) with code the animation start's playing although I expect the button to stay the sprite3. How don't let the Animation play after SetActive(true)?

My Code:

 
using UnityEngine;
using UnityEngine.UI; 

public class ChangeClaim : MonoBehaviour
{
    [SerializeField] 
    private Animator Switch;

    [SerializeField] 
    private Image ClaimBut;

    [SerializeField] 
    private Sprite ButSprite;

    // Start is called before the first frame updateprivate 
    void Update()
    {
        if (PlayerPrefs.GetInt("Compl1") == 1)
        {
            ClaimBut.sprite = ButSprite;
        }

        if (PlayerPrefs.GetInt("Complete1") == 1)
        {
            playSwitch();
        }
    }

    public void playSwitch()
    {
        if (PlayerPrefs.GetInt("Compl1") == 0)
        {
            Switch.SetTrigger("Start");
        }
    }

    public void StopSwitch()
    {
        Switch.SetTrigger("Stop");
        PlayerPrefs.SetInt("Compl1", 1);
    }
}
 

0 Answers

Write your answer here

Top Questions