using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour //private:私有的属性 { public Rigidbody rd;//定义一个组件的属性 // Start is called before the first frame update void Start() { //Debug.Log("游戏开始了"); rd = GetComponent() ;//得到刚体组件,每个方法后面要加(); } // Update is called once per frame void Update() { //Debug.Log("正在游戏中"); //rd.AddForce(Vector3.right); //AddForce:添加一个力,Vector3.right:3d游戏向右的方向 //rd.AddForce(new Vector3(2, 0, 0)); //第二种方法 float h = Input.GetAxis("Horizontal"); // GetAxis:得到一个轴 Horizontal:水平的轴 //-1 1 float v = Input.GetAxis("Vertical"); //w s float j = Input.GetAxis("Jump"); Debug.Log(h); rd.AddForce(new Vector3(h, j, v)*2); } }