Unity【角色/摄像机移动控制】【1.角色移动】

本文主要总结实现角色移动的解决方案。
1. 创建脚本:PlayerController
2. 创建游戏角色Player,在Player下挂载PlayerController脚本
3. 把Camera挂载到Player的子物体中,调整视角,以实现相机跟随效果
3. PlayerController脚本代码如下:

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 5.0f;
    // Start is called before the first frame update
    void Start()
    {
        Transform transform = GetComponent<Transform>();
    }

    // Update is called once per frame
    void Update()
    {      
        Move();
    }
    
    private void Move()
    {
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");
        
        Vector3 moveingVec = new Vector3(horizontalInput, 0f, verticalInput) * Time.deltaTime * speed;
        transform.Translate(moveingVec);
    }    
}
相关推荐
c#上位机16 小时前
halcon图像增强——emphasize
图像处理·人工智能·计算机视觉·c#·上位机·halcon
世洋Blog16 小时前
Unity中图片的内存中占用大小、AB占用大小、内存形式
unity·游戏引擎
熬夜敲代码的小N17 小时前
Unity热更新技术详解
unity·游戏引擎
zxy284722530118 小时前
C#的视觉库Halcon入门示例
c#·图像识别·halcon·机器视觉
c#上位机1 天前
halcon区域变换—shape_trans
图像处理·算法·计算机视觉·c#·halcon
FuckPatience1 天前
C# PropertyGrid(属性编辑框)利用DisplayAttribute实现多语言
c#
小哈龙1 天前
c#安装nuget包--包源映射
c#·nuget
地狱为王1 天前
Cesium for Unity 去除Cesium Logo
unity·游戏引擎·cesium
BuHuaX1 天前
Lua入门
开发语言·unity·junit·c#·游戏引擎·lua
Sunsets_Red1 天前
【算法日常】浅谈倍增(好吧我是用来凑字数的)
c语言·c++·学习·算法·数学建模·c#·学习方法