Unity游戏,我正在尝试在太空中编写无尽的亚军游戏

时间:2020-09-26 13:22:54

标签: unity3d

我是Unity的初学者,我添加了Math。我的游戏中具有钳位功能,但是添加此功能后,我的飞船不会像无尽的跑步者中那样前进:

public class MovePlayer: MonoBehaviour
{
    public float xmin, xmax;

    Rigidbody player;
    float speed=5f;
    
    // Start is called before the first frame update
    void Start()
    {
        player = GetComponent<Rigidbody>();
       
    }

    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        player.velocity = new Vector3(horizontal * speed, 0, speed);

        var clampedPositionX = Mathf.Clamp(player.position.x, xmin, xmax);
       

        player.position = new Vector3(clampedPositionX, 0, speed);
    }
}

0 个答案:

没有答案