帧动画

来源:互联网 发布:网络用语中呦呦的意思 编辑:程序博客网 时间:2024/06/05 03:44

using UnityEngine;
using System.Collections;


public class Animator : MonoBehaviour {


public Sprite[] sprites;
public float framesPerSecond;


private SpriteRenderer spriteRenderer;


// Use this for initialization
void Start () {
spriteRenderer = renderer as SpriteRenderer;
}

// Update is called once per frame
void Update () {
int index = (int)(Time.timeSinceLevelLoad * framesPerSecond);
index = index % sprites.Length;
spriteRenderer.sprite = sprites[ index ];
}
}




using UnityEngine;

using System.Collections;


publicclass cutover :MonoBehaviour {

privateObject[] texmub;

privatefloat fps =5;

privateint nowFram =0;

privatefloat time =0;

Vector3 startingPosition;

Transform cachedTransform;

void Awake(){

cachedTransform = transform;

startingPosition = cachedTransform.localPosition;

}


void HandleFadeUpdate( )

{

float randomXAmount =Random.Range( -1,1 );

float randomYAmount =Random.Range( -1,1 );

Vector3 shakeAmount =newVector3( randomXAmount, randomYAmount,0 ) * .1f;

cachedTransform.localPosition = startingPosition + shakeAmount;

}


// Use this for initialization

void Start () {

texmub =Resources.LoadAll("loading");

}

// Update is called once per frame

void Update () {

DrawAnimation(texmub);

}

void FixedUpdate()

{

HandleFadeUpdate( );

}

void DrawAnimation(Object[] tex)

{

//GUI.DrawTexture(new Rect (Screen.width/3-50,Screen.height/3-50,100,100),(Texture2D)tex[nowFram], ScaleMode.StretchToFill, true, 0);

Texture2D t = (Texture2D)tex[nowFram];

this.renderer.material.mainTexture = t;

time +=Time.deltaTime;

if(time >=1.0 / fps)

{

nowFram++;

time =0;

if(nowFram >= tex.Length)

{

nowFram =0;

}

}

}

}