歩行アニメーションのRunをコメント部の//動いていないときまたはジャンプしてる時はRUNモーションを解除 でfalseすることによって解除してるはずなのですが歩行アニメーションRunが解除できず困っています。自分は初学者なので初歩的なミスをしているかもしれませんがご教授お願いいます。
public class PlayerController : MonoBehaviour { public float JumpForce;//ジャンプ public float max_speed;//最大速度 public float speedForce;//移動速度 private bool isJump; private bool isRun; // private bool isGround; private Animator animator; private Rigidbody2D rb; //private Vector2 ve; // private bool noForce_left; // private bool noForce_right; private const float anispeed = 20.0f;//アニメーションスピード int key = 0; [SerializeField] ContactFilter2D filter2d; // Use this for initialization void Start () { rb = GetComponent<Rigidbody2D>(); animator = GetComponent<Animator>(); //ve = GetComponent<Vector2>(); isJump = false; isRun = false; // noForce_left = false; // noForce_right = false; // isGround = false; } void FixedUpdate() { //地面チェック if (GetComponent<Rigidbody2D>().IsTouching(filter2d)) { // Debug.Log("Filter2d"); isJump = false; // isGround = true; } } // Update is called once per frame void Update () { if (Input.GetKey(KeyCode.Space))//スペースキージャンプ入力 { if (!isJump) { //GetComponent<Rigidbody2D>().AddForce(new Vector2(0, JumpForce)); GetComponent<Rigidbody2D>().AddForce(transform.up * JumpForce); animator.SetBool("Jump", true); isJump = true; } } if (!isJump)//ジャンプしてないときはジャンプモーションを消す。 { animator.SetBool("Jump",false); } float speedx = Mathf.Abs(rb.velocity.x);//移動速度 if (Input.GetKey(KeyCode.RightArrow))//右キー入力 { key = 1; if (speedx < max_speed) { rb.AddForce( transform.right * key * speedForce); } animator.speed = speedx / anispeed; if (isRun == false && isJump == false) { animator.SetBool("Run",true); } }else { } //Debug.Log(rb.velocity.x); if (Input.GetKey(KeyCode.LeftArrow))//左キー入力 { key = -1; if (speedx < max_speed) { rb.AddForce( transform.right * key * speedForce); } animator.speed = speedx / anispeed; if (isRun == false && isJump == false) { animator.SetBool("Run",true); } } //動いていないときまたはジャンプしてる時はRUNモーションを解除 if(key == 0 || isJump == true) { isRun = false; animator.SetBool("Run",false); } if(key != 0)//左右向き修正 { transform.localScale = new Vector3(key,1,1); } Debug.Log(speedx); //摩擦軽減処理 Vector2 v = new Vector2(0.95f,1); Vector2 vj = new Vector2(0.95f,1); if ((speedx > 0) && key == 0) { Debug.Log("慣性"); if (rb.velocity.x > 0) { rb.velocity *= v; } if (rb.velocity.x < 0) { rb.velocity *= v; } } Debug.Log(isJump); // animator.SetBool("Run",false); } private void OnCollisionEnter2D(Collision2D co) { string tagname = co.gameObject.tag; // Debug.Log(tagname); if(tagname == "Block") { //key = 0; //rb.AddForce(transform.right * 0); } if(tagname == "Ground") { } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。