共有回帖数  0  个 
	 
	
	
	
     
          
          
               
				
			 
				
					 
 
            
				   - 
						
						
							 
									
  
 精灵向右走没问题,但是向左走 “走路的动画”就不播放了,请问是什么原因呢?
 下面是绑在身上的代码
 using UnityEngine;
 using System.Collections;
 
 
 
 
 public class jiao : MonoBehaviour {
 public float moveForce = 11;// 刚体2 移动的距离
 public float maxSpeed = 1f;// 刚体2 移动速度
 
 
 public bool facingRight = true; // 面朝向的布尔变量,true为右 false为左
 public object ziti;
 private Animator anim;// Animator简化为 anim
 // Use this for initialization
 void Start () {
 
 }
 
 
 
 void Update () {
 
 }
 void Awake ()
 {
 anim = GetComponentAnimator();// anim 获取 Animator权限
 }
 void FixedUpdate ()
 {
 float h = Input.GetAxis("Horizontal");
 if(h * rigidbody2D.velocity.x  maxSpeed)// h来决定正负 如果 刚体2移动速度小于 maxSpeed
 {
 anim.SetFloat("Speed",h);//这个Speed是动画执行的条件大于0.1
 rigidbody2D.AddForce(Vector2.right * h * moveForce);// 给刚体2 加力
 }
 
 // If the player's horizontal velocity is greater than the maxSpeed...
 if(Mathf.Abs(rigidbody2D.velocity.x)  maxSpeed)
 {
 anim.SetFloat("Speed",h);//这个Speed是动画执行的条件小于0.1
 rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * maxSpeed, rigidbody2D.velocity.y);
 }
 
 
 
 
 
 /*****************************************左右镜像********************************************/
 
 if(h  0 && !facingRight)
 
 Flip();
 
 else if(h  0 && facingRight)
 
 Flip();
 }
 
 
 
 
 void Flip ()
 {
 
 
 facingRight = !facingRight;
 
 
 
 Vector3 theScale = transform.localScale;
 theScale.x *= -1;
 
 
 transform.localScale = new Vector3 (theScale.x, theScale.y, theScale.z);
 }
 
 
 }
 楼主 2015-07-21 21:26 回复 
 
 
   
             
                  
                  
 
 
 
     
	 
  
	Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号
	
	意见反馈 | 
	关于直线 | 
	版权声明 | 
	会员须知