12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 2468|回复: 11
打印 上一主题 下一主题

角色的动作3.2---射击游戏系列教程之三

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-11-21 15:19:00 |只看该作者 |倒序浏览


           下面我们就要声明新增加的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
           


            
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

沙发
发表于 2012-2-15 23:21:45 |只看该作者
好铁多多发,感激分享
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-2-26 23:27:57 |只看该作者
我是老实人,我来也!
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-5-26 23:21:43 |只看该作者
先顶上去,偶要高亮加精鸟!
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-6-21 23:21:21 |只看该作者
很经典,很实用,学习了!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

6#
发表于 2012-6-29 23:24:44 |只看该作者
不错哦,谢谢楼主
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

7#
发表于 2012-7-18 23:20:35 |只看该作者
先顶上去,偶要高亮加精鸟!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

8#
发表于 2012-8-22 00:16:41 |只看该作者
不错 非常经典  实用
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2012-8-31 01:06:09 |只看该作者
都闪开,介个帖子,偶来顶
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2012-10-24 23:27:44 |只看该作者
不会吧,太恐怖了
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-18 09:58 , Processed in 0.086974 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部