- Home /
Animation: how can i use one controller with two animation in the same GameObject
when i collect the shield the animation has entry to animation it play when gameObject is active when the game is playing but i have create a clip on the same gameObject which indicate shield taking hit now i define a parameter when shield get hit to play when OnShieldHit is trigegered but I dont know How to set this on controller window 
Answer by AaronBacon · Aug 22, 2021 at 03:27 PM
You haven't given much information here, but to make the animation switch, You just add the Animator Component to an object and assign the controller:
⠀

⠀
You then need the script to have a reference to the Animator component and Set the Trigger:
⠀
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyNewScript: MonoBehaviour
{
Animator anim;
// Awake will be called when the object is instantiated
public void Awake()
{
anim = GetComponent<Animator>();
}
// Call this function to set your trigger
public void ShieldHitAnim()
{
anim.SetTrigger("OnShieldHit");
}
// Just as an example, this would run the animation when you hit a trigger Collider (Assuming this game is 2D)
protected void OnTriggerEnter2D(Collider2D other)
{
ShieldHitAnim();
}
}
my question was how to use one animator with two animation but I found a solution
Your answer
Follow this Question
Related Questions
GetComponent inexplicably breaking 0 Answers
Best practice character animation [JS] 1 Answer
Button animation error 0 Answers
why does the animation get stuck ? 1 Answer
How to get character animations to transition? Why isn't this working? 0 Answers