You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

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<Rigidbody>();
}
// 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);
}
}
}