Unity3D一个简单的动画混合Demo
2012-11-30 15:17
369 查看
先说说Unity3D关于动画方便的东西,Animation Mixing (动画混合),什么是动画混合呢?举个简单的例子吧,一个模型现在又3种动作,分别是idle、walk、shoot,在Unity3D中一个Layer只能播放二种动画,shoot动作只影响左肩膀的骨骼,而不会影响腿部的动作,所有这里就可以把shoot和walk进行Mixing。
function Start ()
{
//增加一个动画剪辑片段
//
animation.AddClip(animation["shoot"].clip, "shootUpperBody");
animation["shootUpperBody"].AddMixingTransform(transform.Find("mover/gun"));
//@parm 路径
animation["shootUpperBody"].AddMixingTransform(transform.Find("mover/roothandle/spine1"));
//设置动画模式
animation.wrapMode = WrapMode.Loop;
animation["jump"].wrapMode = WrapMode.Clamp;
animation["shoot"].wrapMode = WrapMode.Clamp;
animation["shootUpperBody"].wrapMode = WrapMode.Clamp;
// Put idle and run in a lower layer. They will only animate if our action animations are not playing
animation["idle"].layer = -1;
animation["run"].layer = -1;
animation.Stop();
}
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
{
animation.CrossFade("run");
animation["run"].speed = Mathf.Sign(Input.GetAxis("Vertical"));
}
else
animation.CrossFade("idle");
if (Input.GetButtonDown ("Jump"))
{
animation.CrossFade("jump", 0.3);
}
if (Input.GetButtonDown ("Fire1"))
{
if (animation["run"].weight > 0.5)
animation.CrossFadeQueued("shootUpperBody", 0.3, QueueMode.PlayNow);
else
animation.CrossFadeQueued("shoot", 0.3, QueueMode.PlayNow);
}
function Start ()
{
//增加一个动画剪辑片段
//
animation.AddClip(animation["shoot"].clip, "shootUpperBody");
animation["shootUpperBody"].AddMixingTransform(transform.Find("mover/gun"));
//@parm 路径
animation["shootUpperBody"].AddMixingTransform(transform.Find("mover/roothandle/spine1"));
//设置动画模式
animation.wrapMode = WrapMode.Loop;
animation["jump"].wrapMode = WrapMode.Clamp;
animation["shoot"].wrapMode = WrapMode.Clamp;
animation["shootUpperBody"].wrapMode = WrapMode.Clamp;
// Put idle and run in a lower layer. They will only animate if our action animations are not playing
animation["idle"].layer = -1;
animation["run"].layer = -1;
animation.Stop();
}
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
{
animation.CrossFade("run");
animation["run"].speed = Mathf.Sign(Input.GetAxis("Vertical"));
}
else
animation.CrossFade("idle");
if (Input.GetButtonDown ("Jump"))
{
animation.CrossFade("jump", 0.3);
}
if (Input.GetButtonDown ("Fire1"))
{
if (animation["run"].weight > 0.5)
animation.CrossFadeQueued("shootUpperBody", 0.3, QueueMode.PlayNow);
else
animation.CrossFadeQueued("shoot", 0.3, QueueMode.PlayNow);
}
相关文章推荐
- 命令模式demo-一个简单的动画回放功能
- 仿照imooc《帝堵抢车位动画制作》做的一个超简单停车demo
- unity3d 安装+一个简单的小demo
- 无废话WCF入门教程六[一个简单的Demo]
- 一个简单的Android图片处理Demo
- Java SecurityManager的一个简单Demo
- 在同一个系统里用cxf 实现SOAP 协议和RESTful风格 两种类型的webservice接口(含简单demo)
- 简单的java的一个demo
- springboot整合mybatis一个简单的demo
- Dubbo入门---搭建一个最简单的Demo框架
- Android 属性动画实现一个简单的PopupWindow
- 一个从底部进入的activity转场动画Demo
- [每天一个demo]用c#实现简单的上传文件程序
- [每天一个demo]用c#实现简单的xml操作代码
- [js]用原始的dom对象做的一个简单demo
- 这是用RxJava实现的一个简单demo
- 【Unity Shaders】Reflecting Your World —— 在Unity3D中创建一个简单的动态Cubemap系统
- Hessian+Maven Demo 一个简单的实例(有问题,可以提问,经常在线,源码会粘上连接,可下载)
- 一个简单的JQuery广告动画效果
- unity3d制作小地图(MiniMap)的简单Demo