码迷,mamicode.com
首页 > 其他好文 > 详细

Animator脚本控制代码

时间:2015-03-05 12:50:11      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 
 5 public class AvatarCtrl :MonoBehaviour {
 6 
 7     protected Animator animator;
 8 
 9     public float DirectionDampTime = .25f;
10 
11     void Start () 
12     {
13         animator = GetComponent<Animator>();
14     }
15 
16     void Update () 
17     {
18         if(animator)
19         {
20             //get the current state
21             AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
22 
23             //if we‘re in "Run" mode, respond to input for jump, and set the Jump parameter accordingly. 
24             if(stateInfo.nameHash == Animator.StringToHash("Base Layer.RunBT"))
25             {
26                 if(Input.GetButton("Fire1")) 
27                     animator.SetBool("Jump", true );
28             }
29             else
30             {
31                 animator.SetBool("Jump", false);                
32             }
33 
34             float h = Input.GetAxis("Horizontal");
35             float v = Input.GetAxis("Vertical");
36 
37             //set event parameters based on user input
38             animator.SetFloat("Speed", h*h+v*v);
39             animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
40         }        
41     }             
42 }

 

Animator脚本控制代码

标签:

原文地址:http://www.cnblogs.com/ssw-men/p/4315352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!