Answer the question
In order to leave comments, you need to log in
How to start animation on button click?
Good day. I am new to Unity and Sharps. Faced such a problem:
There is a menu:
On the left is the start button. When you click on it, the animation of the sun should work. The sun increases and covers the canvas completely.
The essence of the problem:
Animation works automatically:
I wrote the following code (the code was rewritten based on several guides a couple of times, so I apologize for the buggy code):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class PlayGame : MonoBehaviour, IPointerClickHandler
{
public Animator SUN;
public void OnPointerClick(PointerEventData eventData)
{
SUN = GetComponent<Animator>();
if (Input.GetButton("Fire1"))
{
SUN.Play("SUN", 1);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Answer the question
In order to leave comments, you need to log in
Dance Macabre Solved the issue by fixing the code and adding a boolean variable in the animator. Thanks for your advice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question