using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpeedController : MonoBehaviour
{
public int speed =10;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){if(Input.GetKeyDown(KeyCode.W))// 判断按下的是哪个按键 w 为加速{
speed +=10;// 加速if(speed >=80){
Debug.Log("Please slow down!");// 达到 80 显示需要减速}}elseif(Input.GetKeyDown(KeyCode.S))// 按下 s 为减速{
speed -=10;// 减速if(speed <=0)// 达到 0 显示需要加速{
speed =0;// 重置速度为 0,因为速度不能为负
Debug.Log("Speed up!");}elseif(speed >=80)// 在超过 80 的情况依然提示减速{
Debug.Log("Please slow down!");}}}}