Using unityengine;using System.Collections; public class Anisprite:monobehaviour {private float myTime = 0; private bool Isplay = true; Anisprit. Sprite (4, 6, 0, 0, 1f), meaning: The map is a 4-column, 6-row animation diagram, the graph starts with coordinates (0,0), the total number of frames given 20 frames, frame rate 24, total time 1 seconds public bool Sprite (int columnsize,in T rowsize, float colframestart, float rowframestart, int totalframes, int framespersecond, float totaltime) {my Time + = Time.deltatime; if (totaltime! = 0 && myTime > totaltime) {isplay = false; MyTime = 0; return isplay; } int index = (int) (Time.time * framespersecond)% Totalframes; Vector2 size = new Vector2 (1.0f/columnsize,1.0f/rowsize); int u = index% ColumnSize; int v = index/columnsize; Vector2 offset = new Vector2 ((U + colframestart) * size.x, (1.0F-SIZE.Y)-(v + rowframestart) * size.y); Renderer.material.mainTextureScale = size; Renderer.material.mainTextureOffset = ofFset return true; }}
U3D 2d sequence Animation code