today's main summary is the built-in animation operations in Unity3d and the implementation of code event authoring animations
1. How to import and perform external animations
In the Project window, first, click to select the animated model we prepared, select the animations bar in the properties panel,
Click "+" in the properties, "-" can add and delete animation segments,
in start and end, you can set the number of start frames and end frames for each animation segment individually.
here is a breakdown of my own animations:
Idle: Represents the Ready action in my animation.
AIM: Indicates the aim action in my animation.
Fire : Indicates the shooting action in my action.
when the above animation section is set up, we use the code to implement, how to control these fragments by the number keys on the keyboard "1" to complete an animation process
first, how to set a key:
in the menu bar, select Edit->roject Setting->input
Select an item in the Input properties panel
name set as Play
Negative button (press the key) is set to the number key "1";
Positive button (release key) is set to the number key "1";
as shown in the following:
OK, we've set the button on the top.
How do you use code to control these fragments to complete an animation process by using the number keys "1" on the keyboard?
below, please see the detailed code:
- Whether it can be controlled
- BOOL Cancontrol=true;
- Update is called once per frame
- void Update ()
- {
- When you press play, we set the number key "1".
- if (Input.getbuttondown ("Play"))
- {
- The animated section of the animation called "Aim" is the target animation section we set above
- GameObject.animation.PlayQueued ("Aim");
- }
- When the 1 key is pressed and the control
- else if (Input.getbuttonup ("Play") &&cancontrol)
- {
- Perform animated fire is the shooting animation section we set above
- GameObject.animation.PlayQueued ("Fire");
- Then we continue to execute Idle, which is what we set up for the animation section.
- GameObject.animation.PlayQueued ("Idle");
- Cancontrol =false;
- }
- Cancontrol =true;
- }
Copy Code
Copy Code
with the simple code above, we can make the series of animation decomposition fragments.
See below:
1. Press the keyboard number key "1" to perform the targeted action, "aim" animation section
2. Release the shooting action performed by the number key "1", Animated fire
3. Loosen the prepare action performed by the number key "1" and proceed with the Idle
2. Using the Unity3d built-in animation system
First, drag and drop the footage into the scene window, set the camera coordinates, add the parallel light
in the upper-right corner of the game window, click , in the pop-up menu, select Add tab->animation
then we'll find a tab called animation (animated) on the game window.
Next, create an animation, and in the animation (animation) tab, clickafter, in
pop up the form to save our animations.
in the Animation tab, we find that there will be a small section of the menu bar, which we'll explain from left to right
1: A frame that is transferred to the animation;
2: The next frame of the jumping knife animation;
3: Text box input indicates any point in time
4: Add a key
5: Indicates an action to add an event (code written)
You can click the "-" sign after the corresponding selection, then select Add a corresponding curve or key in the pop-up menu
below we add rotation.y (rotated in the Y axis) with a value of 360 degrees.
indicates that our object will rotate objects at 360 degrees.
in the Curve area, left-click and drag to select an area
after pressing "F" key, it will be found that this area will be zoomed in locally, so it is convenient for me to view in the case of more curve nodes
Here's a quick introduction to the built-in animations for the next unity3d, which we'll show you about code event animations
as we first defined the object of a camera
and then wrote 2 public event methods.
Camerafaraway (): This method allows us to pull away from the camera perspective.
Cameraclose (): This method allows us to zoom in from camera perspective
then, using the above method, add an event animation to the corresponding event node to achieve a pull-away animation
such as:
angle of view closer to forklift rotation, forklift front clip Drop animation
angle of view pull away forklift swivel, forklift front clip up animation
Unity3d Code realization animation function
- Define a Time variable
- public float time=5.0f;
- Use this for initialization
- void Start () {
- Define an animation curve starting position coordinates of -3.023f, after 5 seconds after the coordinates moved to 2.96f
- Animationcurve curve=animationcurve.linear (0.0f,-3.023f,time,2.96f);
- Add to
- Curve. Addkey (2*time,-3.023f);
- Create a cartoon segment
- Animationclip clip=new Animationclip ();
- Sets the Curve object in the fragment to move in the x-axis
- Clip. Setcurve ("", typeof (Transform), "localposition.x", curve);
- Add the fragment to the animation
- Animation. Addclip (clip, "Test");
- Play a cartoon section called "Test"
- Animation. Play ("Test");
- Loop the animation back
- Animation.wrapmode =wrapmode.loop;
- }
- Update is called once per frame
- void Update () {
- }
Copy Code
Copy Code
you can see that the code creation is similar to the internal setting animation that was summarized yesterday.Dog Planing Learning Net"
a curve is created first and then the fragment is generated by the curve and then the fragment is animated.
Unity3d animation operation and animation implementation