代码之家  ›  专栏  ›  技术社区  ›  Davtho1983

使刚体2d向后移动

  •  0
  • Davtho1983  · 技术社区  · 7 年前

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Fighter_movement : MonoBehaviour
    {
    
        public float thrust;
        public float drag;
        public Rigidbody2D rb;
    
        // Use this for initialization
        void Start()
        {
            rb = GetComponent<Rigidbody2D>();
        }
    
        // Update is called once per frame
        void FixedUpdate()
        {
            float moveHorizontal = Input.GetAxis("Horizontal");
            float moveVertical = Input.GetAxis("Vertical");
    
            Vector2 movement = new Vector2(moveHorizontal, moveVertical);
    
            rb.AddForce(movement);
    
        }
    }
    
    0 回复  |  直到 7 年前