同时按住两个键

把该脚本直接托给要移动的物体即可

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyInput : MonoBehaviour
{
//移动方向枚举
enum MoveDir
{
None,//不动
Up,//上8
Down,//下2
Left,//左4
Right,//右6
UL,//左上7
UR,//右上9
DL,//左下1
DR,//右下3
}

//输入按键常量(之后走配置)
const KeyCode INPUT_UP = KeyCode.W;
const KeyCode INPUT_DOWN = KeyCode.S;
const KeyCode INPUT_LEFT = KeyCode.A;
const KeyCode INPUT_RIGHT = KeyCode.D;

//默认移动方向
private MoveDir moveDir = MoveDir.None;
//按压记录
private bool isUpPress = false;
private bool isDownPress = false;
private bool isLeftPress = false;
private bool isRightPress = false;

//是否可以移动
private bool canMove = true;
//右移动
private Vector3 MOVE_RIGHT = new Vector3(1, 0, 0);
//上移动
private Vector3 MOVE_UP = new Vector3(0, 0, 1);

//外部调控速度
public float speed = 2f;
//移动速度向量
private Vector3 move_speed_dir = Vector3.zero;
//移动距离
private Vector3 move_dis = Vector3.zero;

//控制目标
public Transform target;

void Update(https://www.qqtn.com/wm/nanshengwm_3.html)
{
CheckInputKey();
CheckMoveDir();
}
void FixedUpdate()
{
CheckMove(http://www.amjmh.com);
}
//检测输入按键
void CheckInputKey()
{
//检测单一输入
foreach (KeyCode kcode in System.Enum.GetValues(typeof(KeyCode)))
{
--------------------- 

原文地址:https://www.cnblogs.com/hyhy904/p/11277807.html