How to play different animations with different UI button presses.
Just a fore note, I am a uber newbie on Unity, scripting is not my forte.
Using an HTC Vive, I have created a UI canvas with 4 buttons which is attached to my left controller. With my right controller I can click on these 4 buttons. When each button is pressed I want it to turn objects on and off in my scene, I have done this through an animator controlling 4 animations. The problem I have now is how to link the two together. What I think needs to happen is that when a button is pressed it sets the trigger for the corresponding animation as true, whilst setting the triggers for the other three animations as false. These triggers are applied to animator transitions. I think I'm right in that the script for this would be added to the canvas with the buttons as a 'Manager' script. The closest Ive got to anything like this is turning one animator on and off. Please if anyone can help me I'd really appreciate it.
Answer by bluehorizons · Jul 26, 2017 at 02:53 PM
so I figured out simple solution. By adding this code with three others like it, simply changing the "Original" (which is my trigger name) with the other trigger names required, and saving each script with unique names. I then added each script to the game object that has the animator. Within the animator it is a case of having a web of triggers. Hope this helps anyone stuck with a similar problem!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Original : MonoBehaviour
{
private Animator menuAnim;
private bool menuOn = false;
void Awake()
{
menuAnim = GetComponent<Animator>();
}
public void BeginMenu()
{
if (!menuOn)
{
menuAnim.SetTrigger("Original");
}
}
}
Your answer
Follow this Question
Related Questions
UI flickering when in VR 1 Answer
Smooth UI sprite animation. 1 Answer
How do I make a UI Button play animation? 1 Answer
GVR circular progressive bar 1 Answer