Now we will do a different animation than death animation on demand, but it will be based on the same principles. We will make an example animation that when our object, which we control, eg. A ball will hit a cube, then this cube will fly up and come back, the simplest example that may you could easily understand how to make animation on demand, we will have to create two animations, one that won’t do anything and second that will be move the object up and down, if you do not know how to create an animation
click here
So, first create an animation, do nothing in animation options and save it
Then create another animation, add add property transform then position, then set the animation like this:
Of course, you can create the second animation in way you want, I just did it for educational purposes.
Once you have created this animation, go to the “Animator” window next to the “Game” window, these rectangles, apart from “Any State” and “Entry”, are the animations you have created. On the left side of the “parameters” window, press this small plus and select “Trigger“, name it as you want, then right-click on the animation rectangle that symbolized idle, and select “Make Transition” and aim the arrow on the second animation, you have to do this because the animation will go from idle to float up, with the second animation you do the same, then press the arrow that points to the animation that in my case is floating up and down and press this plus on the bottom right and give it the name as you gave to that parameter “Trigger”.
The whole looks like this:
I to named the animation of in action “anima” and the second “anima1”. And all of this now just need to assign a very simple script below to the object that we want to animate and assign the tag “Player” to the object we control, to assign the tag click on the object you control and click on the top “Tag” window and select the tag “Player”.
using UnityEngine;
using System.Collections;
public class Animation : MonoBehaviour {
public Animator animator;
void OnCollisionEnter(Collision col)
{
if(col.gameObject.tag=="Player")
{
animator.SetTrigger ("begin");
}
}
}
If you recognise it as useful, share it with others so that others can also use it and leave upvote and follow if you wait for next articles :) .
That’s all I wanted to describe today, hold on !!!!!