简体   繁体   中英

AR Animation issue in Unity

I am trying a animation with AR using unity and Metaio sdk. I have to play that animation step by step when I try the below script it works perfect on ipad and android mobile device.

         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:-

    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. I am new in Unity and AR developement

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.

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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM