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.设置