1,動畫系統配置
創建游戲對象并添加Animation組件,然后將動畫文件拖入組件。

進入動畫文件的Debug屬性面板

選中Legacy屬性

選中游戲對象,打開Animation編輯窗口

添加動畫變化屬性

需改關鍵幀的屬性值

配置完成后運行即可得到動畫效果
2,代碼控制動畫
Play("ation 1" );,播放動畫,傳入參數為動畫名字
Stop("ation 1") ,停止動畫,傳入參數為動畫名字
CrossFade("ation 1", 0.5f); ,有過度的切換動畫,傳入參數(動畫名字,過度時間)
實例代碼
- using?UnityEngine;??
- using?System.Collections;??
- ??
- public?class?NewBehaviourScript?:?MonoBehaviour?{??
- ???????
- ????Animation?m_anim;??
- ????private?float?scaleW?=?1.0f;??????????
- ????private?float?scaleH?=?1.0f;??????????
- ??????
- ????void?Start?()?{??
- ??????????
- ????????m_anim?=?GetComponent<Animation>();??
- ????????if?(!m_anim.isPlaying)??
- ????????{??
- ??????????????
- ????????????m_anim.CrossFade("ation?1",?0.2f);??
- ????????}??
- ????}??
- ??????
- ??????
- ????void?Update?()?{??
- ????????scaleW?=?(float)Screen.width?/?800;???????
- ????????scaleH?=?(float)Screen.height?/?480;??????
- ????}??
- ????void?OnGUI()??
- ????{??
- ????????GUI.skin.button.fontSize?=?(int)(25?*?scaleW);??????????
- ??
- ????????if?(GUI.Button(new?Rect(70?*?scaleW,?50?*?scaleH,?90?*?scaleW,?40?*?scaleH),?"ation?1"))??
- ????????{??
- ????????????m_anim.Play("ation?1"?);??
- ????????}???
- ????????if?(GUI.Button(new?Rect(70?*?scaleW,?110?*?scaleH,?90?*?scaleW,?40?*?scaleH),?"imation"))??
- ????????{??
- ????????????m_anim.Play("imation");??
- ????????}??
- ????????if?(GUI.Button(new?Rect(70?*?scaleW,?170?*?scaleH,?220?*?scaleW,?40?*?scaleH),?"有過度播放ation?1"))??
- ????????{??
- ????????????m_anim.CrossFade("ation?1",?0.5f);??
- ????????}??
- ????????if?(GUI.Button(new?Rect(70?*?scaleW,?230?*?scaleH,?220?*?scaleW,?40?*?scaleH),?"有過度播放imation"))??
- ????????{??
- ????????????m_anim.CrossFade("imation",?0.5f);??
- ????????}??
- ??????????
- ????}??
- }??
將代碼添加到游戲對象,運行游戲。

?