Triggering GUI animation on prefab pickup
I'm trying to create a GUI that isn't intrusive (something similar to Spyro The Dragon). So far I have it so that the GUI is off screen until a button is pressed using a bit of code in the PlayerController scrip.
if (Input.GetButtonDown("YButton"))
{
animUI.SetBool("isDropdown", true);
}
if (!Input.GetButtonDown("YButton"))
{
animUI.SetBool("isDropdown", false);
}
So when I hit the YButton on my controller the UI drops down into view (showing item count and rotating sprite icons for said items) and then returns to its position off screen. I also want the animation to trigger when an item of a specific tag is picked up, too. I don't quite know how to do this, however. OK, first off, the Player, the pickups and the UI all have their own Animator (I don't know if having them all use the same animator is possible), and the animation of the UI is transitioned into with a bool. I've tried to trigger the animation in the script on the pickups prefab that adds to the counter in the UI and destroys the game objects as the player collides with them, referring to the UI's Animator in the inspector.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VacPickups : MonoBehaviour
{
public int vacCount;
public GameObject pickupEffect;
public Animator animUI;
private void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
animUI.SetBool("isDropdown", true);
FindObjectOfType<GameManager>().AddVac(vacCount);
Instantiate(pickupEffect, transform.position, transform.rotation);
Destroy(gameObject);
}
}
}
But the animation is never triggered when the pickups are destroyed. So far I can only trigger the animation when i hit the YButton. Does anyone have any suggestions on how to trigger the UI to animate when the pickups are destroyed? Thank you for any input.
Your answer
Follow this Question
Related Questions
Problem with animated image on canvas 0 Answers
How to apply a .anim file to another object 0 Answers
How can I play an animation with a script? 1 Answer
Is it possible to for an Animator component of a UI Panel to receive triggers from a child Toggle? 0 Answers
Help with 8-DOM Weapon Sprite Issue 0 Answers