[Unity3D self-study record] about Animation (animation) backward playback method

How to make an animation play backwards,

The principle is very simple, the code is as follows:

using UnityEngine;
using System.Collections;

public class DJH_Animation : MonoBehaviour {
    public GameObject AnimationObj;//带有动画的对象
    
	// Use this for initialization
	void Start () {
        AnimationObj.animation["AnimationName"].time = AnimationObj.animation["AnimationName"].clip.length;
        AnimationObj.animation["AnimationName"].speed = -1.0f;  
        AnimationObj.animation.CrossFade("AnimationName");
	}
	
}


Create an object with animation.

AnimationObj.animation["AnimationName"].time = AnimationObj.animation["AnimationName"].clip.length;

AnimationName is the name of the animation.

Giving the length of the animation to the time of the animation is actually to reverse the animation and give the end to the beginning of the animation.

AnimationObj.animation["AnimationName"].speed = -1.0f;  

Then set the speed of the animation to -1.0f, there is no need to explain this~


This is roughly the steps.



Guess you like

Origin blog.csdn.net/hackdjh/article/details/21089413