纳金网

标题: 角色的动作3.2---射击游戏系列教程之三 [打印本页]

作者: 会飞的鱼    时间: 2011-11-21 15:19
标题: 角色的动作3.2---射击游戏系列教程之三


           下面我们就要声明新增加的HandleAnimation () 函数了。看下面代码可以发现,此函数只是起到一个调用,真正起作用的是其所调用的FindAnimation(),ProcessAnimation() 这两个函数,搞清楚这个函数和用途,也就明白此章节所讲的了。FindAnimation()这个函数其实是检测角色是处于什么状态,是在移动呢还是停 止,紧接着ProcessAnimation()这个函数根据角色当前的状态是行走还是停止来处理图片序列的播放等。
           



           void HandleAnimation () // handles all animation
           

           {
           

           FindAnimation();
           

           ProcessAnimation();
           

           }
           

           void FindAnimation ()
           

           {
           

           if (inputMovement.magnitude > 0)
           

           {
           

           currentAnimation = animationWalk;
           

           } else {
           

           currentAnimation = animationStand;
           

           }
           

           }
           

           void ProcessAnimation ()
           

           {
           

           animationTime -= Time.deltaTime; // animationTime -= Time.deltaTime; subtract
           

           the number of seconds passed since the last frame, if the game is***nning at 30 frames per second the
           

           variable will subtract by 0.033 of a second (1/30)
           

           if (animationTime <= 0)
           

           {
           

           frameNumber += 1;
           

           // one play animations (play from start to finish)
           

           if (currentAnimation == animationMelee)
           

           {
           

           frameNumber =
           

           Mathf.Clamp(frameNumber,meleeAnimationMin,meleeAnimationMax+1);
           

           if (frameNumber > meleeAnimationMax)
           

           {
           

           /* if (meleeAttackState
           

           == ***e) // this has been commented out until we add enemies that will attack with their evil alien
           

           claws
           

           {
           

           frameNumber =
           

           meleeAnimationMin;
           

           } else {
           

           currentFrame =
           

           frameStand;
           

           frameNumber =
           

           standAnimationMin;
           

           }*/
           

           }
           

           }
         

           // cyclic animations (cycle through the animation)
           

           if (currentAnimation == animationStand)
           

           {
           

           frameNumber =
           

           Mathf.Clamp(frameNumber,standAnimationMin,standAnimationMax+1);
           

           if (frameNumber > standAnimationMax)
           

           {
           

           frameNumber = standAnimationMin;
           

           }
           

           }
           

           if (currentAnimation == animationWalk)
           

           {
           

           frameNumber =
           

           Mathf.Clamp(frameNumber,walkAnimationMin,walkAnimationMax+1);
           

           if (frameNumber > walkAnimationMax)
           

           {
           

           frameNumber = walkAnimationMin;
           

           }
           

           }
           

           animationTime += (1/animationFrameRate); // if the
           

           animationFrameRate is 11, 1/11 is one eleventh of a second, that is the time we are waiting before we
           

           play the next frame.
           

           }
           

           spriteSheetCount.y = 0;
           

           for (i=(int)frameNumber; i > 5; i-=5) // find the number of frames down the
           

           animation is and set the y coordinate accordingly
           

           {
           

           spriteSheetCount.y += 1;
           

           }
           

           spriteSheetCount.x = i - 1; // find the X coordinate of the frame to play
           

           spriteSheetOffset = new Vector2(1 - (spriteSheetCount.x/spriteSheetTotalRow),1 -
           

           (spriteSheetCount.y/spriteSheetTotalHigh)); // find the X and Y coordinate of the frame to display
           

           renderer.material.SetTextureOffset ("
           


            _
           
           MainTex", spriteSheetOffset); // offset
           

           the texture to display the correct frame
           

           }
         

           到目前为止,如果一切顺利的话,切换到游戏模式,角色已可以正常的行走了,接下来的部分是对上面新增加的代码的一个分段讲解....当然,你想省事的话,直接将本节教程最后的附件中的AIscript.cs文件下载,直接复制代码即可!
           



           出处:
           
            www.unity3d8.com
           


            
         

作者: 晃晃    时间: 2012-2-15 23:21
好铁多多发,感激分享

作者: 奇    时间: 2012-2-26 23:27
我是老实人,我来也!

作者: tc    时间: 2012-5-26 23:21
先顶上去,偶要高亮加精鸟!

作者: tc    时间: 2012-6-21 23:21
很经典,很实用,学习了!

作者: 晃晃    时间: 2012-6-29 23:24
不错哦,谢谢楼主

作者: 菜刀吻电线    时间: 2012-7-18 23:20
先顶上去,偶要高亮加精鸟!

作者: 晃晃    时间: 2012-8-22 00:16
不错 非常经典  实用

作者: 菜刀吻电线    时间: 2012-8-31 01:06
都闪开,介个帖子,偶来顶

作者: 奇    时间: 2012-10-24 23:27
不会吧,太恐怖了

作者: tc    时间: 2012-12-4 23:19
响应天帅号召,顶

作者: 晃晃    时间: 2013-3-21 23:30
俺是新人,这厢有礼了!





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5