[英]AR Animation issue in Unity
I am trying a animation with AR using unity and Metaio sdk. 我正在尝试使用unity和Metaio sdk在AR中制作动画。 I have to play that animation step by step when I try the below script it works perfect on ipad and android mobile device.
当我尝试以下脚本时,我必须逐步播放该动画,该脚本在ipad和android移动设备上完美运行。
Variable declaration
********************
public GUIStyle buttonTextStyle;
public Texture aTexture;
private int curretnStep=1;
GameObject gameObject;
float SizeFactor;
Texture2D texture;
Animator CMTD42M ;
bool isplaystarted = false;
int[] videolengtharray = new int[6];
int CurrentFrame=0;
bool islocked = false;
*************
if (GUIUtilities.ButtonWithText (new Rect (Screen.width - 160, Screen.height - 100, 160, 100), "Next", null, buttonTextStyle)) {
CMTD42M.speed=1;
switch (curretnStep) {
case 1:
CMTD42M.Play ("First");
break;
case 2:
CMTD42M.Play ("Second");
break;
case 3:
CMTD42M.Play ("Third");
break;
case 4:
CMTD42M.Play ("Four");
break;
case 5:
CMTD42M.Play ("Five");
break;
case 6:
CMTD42M.Play ("Six");
break;
}
curretnStep++;
//isplaystarted = true;
}
As I am running this script on Epson Moverio(Glasses) it dont take the button click event,so I used onMouseButtonDown As below script:- 当我在Epson Moverio(Glasses)上运行此脚本时,它不会发生按钮单击事件,因此我使用了onMouseButtonDown如下脚本:-
if (Input.GetMouseButtonDown (0)) {
if ((new Rect (Screen.width - 160, Screen.height - 100, 160, 100)).Contains (Event.current.mousePosition))
{
CMTD42M.speed=1;
switch (curretnStep) {
case 1:
CMTD42M.Play ("First");
break;
case 2:
CMTD42M.Play ("Second");
break;
case 3:
CMTD42M.Play ("Third");
break;
case 4:
CMTD42M.Play ("Four");
break;
case 5:
CMTD42M.Play ("Five");
break;
case 6:
CMTD42M.Play ("Six");
break;
}
curretnStep++;
}
}
the animation is not playing step by step. 动画不能逐步播放。 it plays in different order..
它以不同的顺序播放。
Can ANybody help me, or please guide where I made mistake. ANybody可以帮助我,还是请指导我做错了什么。 I am new in Unity and AR developement
我是Unity和AR开发的新手
I get that Mouse-event proper. 我正确地了解了鼠标事件。 Is the problem in animation or in mouse click.. Please help..
是动画问题还是鼠标单击问题。.请帮助..
Thanks bl0z0, I have written this code in OnGUI() function. 谢谢bl0z0,我已经在OnGUI()函数中编写了此代码。
I finally solve my problem.. I am not getting the reason behind it. 我终于解决了我的问题。我没有找到背后的原因。
The problem was in variable current step, when I do 问题是在可变电流步骤中,当我这样做时
curretnStep++;
it was incremented by 2,not by 1.(only in Epson Moverio) so it was not taking proper switch-cases and animation plays wrong. 它增加了2,而不是增加了1(仅在Epson Moverio中使用),因此未采取适当的切换方式,动画播放出错。
apparently that device (Epson Moverio) has a higher frame rate than standard devices (mobiles, I guess those glasses run on Android) and the fact that you got true on Input.GetMouseButtonDown(0) twice make me think that is actually a bug (for that platform). 显然,该设备(Epson Moverio)的帧频比标准设备(移动设备,我猜那些眼镜运行在Android上)要高,而且您在Input.GetMouseButtonDown(0)上输入的是正确的事实使我认为这实际上是一个错误(该平台)。
I don't really recommend to use OnGUI because its kind of heavy for mobile development, what you can do is maybe work with a flag that goes off when you plays an animation and only goes on when the animation that you played is finished. 我真的不建议使用OnGUI,因为它对移动开发很繁重,您可以做的是使用一个标志,该标志在播放动画时会关闭,而在播放的动画完成后才继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.