做动画!

做动画

  1. 用序列帧

 

调用文件:

void RoleUp()

    {

       BroadcastMessage("Move", 2.0);

       controller.Move(Vector3.up * Time.deltaTime*currentVel);

    }

 

被调用文件SimpleSprite.cs:

using UnityEngine;

using System.Collections;

 

public class SimpleSprite : MonoBehaviour

{

    //Setup Animations

    public Texture[] animation0;

    public Texture[] animation1;

    public Texture[] animation2;

    public Texture[] animation3;

//  public Texture[] animation4;

//  public Texture[] animation5;

//  public Texture[] animation6;

//  public Texture[] animation7;

//  public Texture[] animation8;

//  public Texture[] animation9;

    public bool billboard = false;

   

    // Animation To Play

    private Camera cameraToLookAt;

      

    public float timeElasped = 0;

    public int  icurFrame = 0;

    public float fps = 10;

   

    private Quaternion rotation;

 

    private Vector3 position;

   

    public MeshRenderer mesh;

 

 

 

   

    // Use this for initialization

    void Start ()

    {  

       //cameraToLookAt = Camera.main;

       //rotation = Quaternion.Euler(0, 0, 0);

       //rotation = new Quaternion (0, 0, 0, 0);

       //transform.position = new Vector3(358, 58, -4);

    }

   

    // Update is called once per frame

    void Update ()

    {

//     position = transform.position; 

//     position.z = -15f;

//     transform.position = position;

//     transform.rotation = rotation;

       //Debug.Log(position);

   

//     if(transform.position.y<-3)

//     {

//         position.x=358f;

//         position.y=58f;

//         position.z=-7f;

//         transform.position=position;

//     }

      

    }

   

    void Move(int animationplay)

    {

       timeElasped += Time.deltaTime;

       if(timeElasped >= 1.0 / fps)

       {     

           timeElasped = 0;

           icurFrame++;

           if(icurFrame >= animation0.Length)

           {

              icurFrame = 0;   

           }  

          

           switch(animationplay)

           {            

              case 0:

              {

                  //Debug.Log("left icurFrame---------------" + icurFrame);

                  mesh.renderer.material.mainTexture = animation0[icurFrame];

                  break;

              }  

   

              case 1:

              {

                  mesh.renderer.material.mainTexture = animation1[icurFrame];

                  break;

              }

                 

              case 2:

              {

                  mesh.renderer.material.mainTexture = animation2[icurFrame];

                  break;

              }

                 

              case 3:

              {

                  mesh.renderer.material.mainTexture = animation3[icurFrame];

                  break;

              }

           }

       }

    }

 

}

 

 

2.用NGUI做动画

posted @ 2013-05-08 14:26  六界剑仙  阅读(136)  评论(0)    收藏  举报