小编Adi*_*Adi的帖子

如何在Unity中设置刚体的最大速度?

似乎没有任何效果,玩了几个小时,从谷歌复制并粘贴了“解决方案”,但没有。
更改 maxSpeed 变量不会执行任何操作。物体仍然像巴里·艾伦一样飞过屏幕。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour 
{

    [Range (0, 5)]public int speed;
    public Rigidbody2D rb2D;
    public Vector3 veloc;
    public float maxSpeed;

    void Start () 
    {
        rb2D = GetComponent<Rigidbody2D> ();
        speed = 4;
        maxSpeed = 0.01f;
        veloc = GetComponent <Rigidbody2D>().velocity;
    }

    void Update () 
    {
        if(Input.GetKey(KeyCode.W))
        {
            rb2D.AddForce (Vector3.up * speed);
        }
        if(Input.GetKey(KeyCode.S))
        {
            rb2D.AddForce (-Vector3.up * speed);
        }
        if(Input.GetKey(KeyCode.D))
        {
            rb2D.AddForce (Vector3.right * speed);
        }
        if(Input.GetKey(KeyCode.A))
        {
            rb2D.AddForce (-Vector3.right * speed); …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

unity-game-engine ×1