using UnityEngine;
using System.Collections;

public class HeroColtrol : MonoBehaviour
{
    private Rigidbody2D HeroRd;
    public float MoveSpeed;
    public float JumpHeight;
    void Awake()
    {
        HeroRd = transform.GetComponent<Rigidbody2D>();
    }


    void FixedUpdate()
    {
        float h = Input.GetAxis("Horizontal");
        if (!h.Equals(0))
        {
            HeroRd.velocity = new Vector2(h * MoveSpeed, HeroRd.velocity.y);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (HeroRd.velocity.y.Equals(0))
                HeroRd.velocity = new Vector2(HeroRd.velocity.x, JumpHeight);
        }

    }

}

unity3d 2D游戏,角色移动与跳跃
图片.png

相关文章:

  • 2022-02-20
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2022-01-01
  • 2021-11-03
  • 2021-05-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-01-01
相关资源
相似解决方案