纳金网

标题: unity3d动作事件运用(二) [打印本页]

作者: 会飞的鱼    时间: 2011-11-14 15:26
标题: unity3d动作事件运用(二)



            Setting Animation Events
            




           Once you have your animation state selected ( I have the walk animation state selected), you can begin adding events. If you bring up Scene view behind, you can see your model actually moving when you s***b the timeline. See below image.
         

            
           


           Where to put the animation events
         

           Once you s***b your animation to know where you want an event. You can create an event there (right most icon on the play toolbar). If you select the event, you will notice that there are no options for what it wants to do. We will do that next.
         


            Binding functions to Events
            




           In order for the animation events to to fire off a function for an event, it needs to know where it is. The way animation events work, there has to be a script attached to the gameobject that has the animation component as well. See below.
         

            
           






           Adding a script for animation events
         

           I added a script to the same place the animation component is. You can create functions in there and that is what the animation window tool will see.
         

           public void walkAnimationEvent()
         

           {
         

           Debug.Log("Foot is down walking");
         

           audio.PlayOneShot(walkSound);
         

           audio.volume = 0.4f;
         

           }
         

           Once you add a function like the one above, you can go back to your animation window and select the event again. This time your new function will show up. When you***n the game now, you will see that the event will fire every time the animation hits that frame. Success!
         

            
         

           Extra Credit
           

           Looping animations such as walking are a little more complicated from what I have done with them. Since they are looping, sometimes the fire off more than they should. To solve it, I have add an enum that has what animation state the character is in. It will only do the function if it is firing AND if it is in the right state. You can download the “Witch Training Project” to see if you are interested. It still needs a little tweaking since the walk sound lingers a little too long – but you the idea
           

           I haven’t seen this in-depth of animation events on many blog posts, so hopefully this will help in understanding and using them in your project. Happy game making!
         

            
         

作者: 菜刀吻电线    时间: 2012-1-19 22:58
秋天的落叶已飘远,冬日的暖阳已降临,春天的故事在萌芽,夏日的清凉在期待。新年的钟声提前为你敲响,HAPPYNEWYEAR!

作者: C.R.CAN    时间: 2012-1-20 23:30
林志玲,娇滴滴,祝你新年一定要好好的啦!小沈阳,笑嘻嘻,祝你新年一定要杠杠的哈!春晚群星,闹哄哄的,祝你新年辞旧迎新开创新纪元!

作者: 奇    时间: 2012-1-26 23:26
笑声,欢天喜地;幸运,铺天盖地;才情,经天纬地;财气,呼天唤地;豪气,遮天盖地;福气,惊天动地;春节,冰天雪地;快乐,翻天覆地!

作者: tc    时间: 2012-3-8 23:24
百度的叫度娘,网易的叫易娘,新浪内部还在为是叫新娘还是浪娘而争论不休!……不管你们是企鹅的额娘,豆瓣的伴娘,还是华为的伪娘,都要记得,淘宝才是你们的亲娘啊!亲!!

作者: 浩劫    时间: 2012-3-9 20:09

作者: 菜刀吻电线    时间: 2012-4-3 23:32
百度的叫度娘,网易的叫易娘,新浪内部还在为是叫新娘还是浪娘而争论不休!……不管你们是企鹅的额娘,豆瓣的伴娘,还是华为的伪娘,都要记得,淘宝才是你们的亲娘啊!亲!!

作者: 晃晃    时间: 2012-4-30 23:19
不错 非常经典  实用

作者: 晃晃    时间: 2012-7-25 23:20
先垫一块,再说鸟

作者: 奇    时间: 2012-9-27 23:23
呵呵,很好,方便罗。

作者: tc    时间: 2013-2-12 23:27
你们都躲开,我来顶





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