其他分享
首页 > 其他分享> > Unity2020 控制刚体运动

Unity2020 控制刚体运动

作者:互联网

1.代码

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class Player : MonoBehaviour
 6 {
 7     public float speed = 1;
 8     private Rigidbody rd;
 9 
10     // Start is called before the first frame update
11     void Start()
12     {
13         rd = GetComponent<Rigidbody>();
14     }
15 
16     // Update is called once per frame
17     void Update()
18     {
19         float h = Input.GetAxis("Horizontal");
20         rd.AddForce(new Vector3(h, 0, 0) * speed);
21         float v = Input.GetAxis("Vertical");
22         rd.AddForce(new Vector3(0, 0, v) * speed);
23     }
24 }

2.设置

 

 

 

标签:frame,float,System,rd,using,运动,speed,Unity2020,刚体
来源: https://www.cnblogs.com/huihui5471/p/15690860.html