控制玩家的移动

创建Player脚本:

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

public class Player : MonoBehaviour {
    public float moveSpeed;//坦克移动速度

    void Start () {
        
    }

    void Update () {
        float h = Input.GetAxisRaw("Horizontal");//获取水平输入
        float v = Input.GetAxisRaw("Vertical");//获取垂直输入
        transform.Translate(Vector3.right*h*moveSpeed*Time.deltaTime);//水平移动
        transform.Translate(Vector3.up * v * moveSpeed * Time.deltaTime);//垂直移动
    }
}

给坦克主角增加Player脚本,设置移动速度

猜你喜欢

转载自www.cnblogs.com/kubll/p/10828781.html
今日推荐