android+unity3D遊戲開發之動畫的播放

來源:互聯網
上載者:User

       我們今天來控制小人的走路,跑,死,和殺招。這可是真正的動畫哦,我們先來看看協助文檔裡面的代碼和animation有關的屬性,然後我解釋一下,再舉個我的列子讓大家體會一下;

 

1.首先把我們的動畫.fbx檔案放到Hierarchy中,選中它,在Inspector裡面看到如所示的情況:

    註: 其中Play Automatically指的是自動播放;

 

2.我們再看看協助文檔的代碼吧

 

        animation.Play();

    這段代碼就是指的動畫的播放,如果寫這段代碼的話,就別選Play Automatically啦。
            

      animation.Play("walk");

   這段代碼就是控制另一個名字為walk的動畫啦。

 

3.大家再來看看我的小人動作的例子吧:

    看看代碼:         

function OnGUI() {      if(GUI.Button(Rect(100,70,70,20),"walk")){      animation.Play("walk");      }      if(GUI.Button(Rect(100,100,70,20),"run")){      animation.Play("run");      }      if(GUI.Button(Rect(100,130,70,20),"attack")){      animation.Play("attack");      }      if(GUI.Button(Rect(100,160,70,20),"die")){      animation.Play("die");      }       if(GUI.Button(Rect(100,190,70,20),"stop")){      animation.Play("Take 001");      }}

我這裡有五個動作,我們看看效果吧。

如果大家看不明白的話,可以和我交流一下,一起討論哈。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.