1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//控制角色移动、生命、动画等
public class NewBehaviourScript : MonoBehaviour
{
public float speed = 5f;//移动速度
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
float moveX = Input.GetAxisRaw("Horizontal");//控制水平方向移动,A:-1,D:1,0
float moveY = Input.GetAxisRaw("Vertical");//控制垂直方向W1 S-1 0

Vector2 position = transform.position;
position.x +=moveX * speed * Time.deltaTime;
position.y +=moveY * speed * Time.deltaTime;
transform.position = position;
}

}