📜  unity 2d 自上而下移动脚本 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:05.439000             🧑  作者: Mango

代码示例2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{


    public float moveSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;

    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    void FixedUpdate()
    {
        rb.MovePosistion(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
}