unity手指缩放控制动画的播放和倒播

一个算是很酷炫的展示方式吧,两根手指的移动距离等于动画播放的NormallizedTime,有时候可以试一下
public Animation ani;//注意:导入的模型动画需要将动画模式设置为legacy,否则不播放,需要将animator取消,添加 //animation组件,animator的还不知道怎么跟随手指移动进行来回播放,有会的欢迎评论讨论
void update()
{
if (Input.touchCount>1)
{
newTouch1 = Input.GetTouch(0);
newTouch2 = Input.GetTouch(1);
if (newTouch2.phase==TouchPhase.Began)
{
oldTouch2 = newTouch2;
oldTouch2 = newTouch1;
return;
}
float oldDistance = Vector2.Distance(oldTouch1.position, oldTouch2.position);
float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position);
//两个距离之差,为正表示放大手势,为负表示缩小
float offset = newDistance - oldDistance;
oldTouch1 = newTouch1;
oldTouch2 = newTouch2;
ani[“Take 001”].normalizedTime += offset * 0.005f;//动画时间等于手指缩放的距离
ani[“Take 001”].speed = 0;//这一句很关键
if (ani[“Take 001”].normalizedTime<=0)
{
ani[“Take 001”].normalizedTime = 0;
}
if (ani[“Take 001”].normalizedTime >= 1)
{
ani[“Take 001”].normalizedTime = 1;
}
}

上一篇:Array.Copy vs Skip and take in c#


下一篇:100-days: eleven