I am trying to render an animation on button click, but for some reason the animation is not rendering.
The animation is a coin with a trail moving from the button to a coin bag on my GUI in a game.
The button name is called “collectedCoinsGreenBtn” and an animation component with the script is attached to the Inspector.
Here is a script to see the animation call function.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class CoinTrail : MonoBehaviour {
// public game object for coin image
public GameObject CoinsCollectGreen;
void Start ()
{
CoinsCollectGreen.gameObject.SetActive (false);
}
public void RenderTrail ()
{
CoinsCollectGreen.gameObject.SetActive (true);
GetComponent<Animation> ().Play ("GreenCoin");
}
}
Here is an image of the Inspector with the button OnClick with the RenderTrail function in place.