返回

c#-我的播放器在未编程的情况下在动画之间切换

发布时间:2022-08-18 19:43:36 188
# flask
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField]
    float moveForce = 10f;

    [SerializeField]
    float jumpForce = 11f;

    float movementX;

    Rigidbody2D myBody;

    Animator Anim;

    private SpriteRenderer sr;

    string WALK_ANIMATION = "Walk";

    private void Update()
    {
        playerMoveKeyboard();
        animatePlayer();
    }

    private void Awake()
    {
        myBody = GetComponent();
        Anim = myBody.GetComponent();
        sr = GetComponent();



    }
    void playerMoveKeyboard()
    {
        movementX = Input.GetAxisRaw("Horizontal");
        transform.position += new Vector3(movementX, 0f, 0f) * moveForce * Time.deltaTime;
    }
    void animatePlayer()
    {
        if(movementX > 0)
        {
            Anim.SetBool(WALK_ANIMATION, true);
            sr.flipX = false;
        }
        else if (movementX < 0)
        {
            Anim.SetBool(WALK_ANIMATION, true);
            sr.flipX = true;
        }
        else
        {
            Anim.SetBool(WALK_ANIMATION, false);
        }



    }
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像