using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { public float health = 100; // 角色生命值 public Rigidbody rb; public int speed = 20; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { if (health <= 0) { Destroy(gameObject); } // 前 if (Input.GetKey(KeyCode.W)){ rb.AddForce(transform.forward * speed); } // 后 if (Input.GetKey(KeyCode.S)) { rb.AddForce(transform.forward * -speed); } // 右 if (Input.GetKey(KeyCode.D)) { rb.AddForce(transform.right * speed); } // 左 if (Input.GetKey(KeyCode.A)) { rb.AddForce(transform.right * -speed); } // 跳 if (Input.GetKey(KeyCode.Space)) { rb.AddForce(transform.up * speed); } } }