- Home /
issue rendering animation on button click
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.
Answer by Trevdevs · Jun 25, 2018 at 11:32 PM
Have you tried manually setting the animation clip in the animation component?
secondly in your script add a debug.log("test") to the button click to make figure out if its the button click or the animation itself thats the problem
I am using Unity 2018, which does not have Animator Components anymore. Unity did away with them. I tried a debug.log test and everything checks out to function correctly.