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);
    }    
}
相关推荐
老朱佩琪!31 分钟前
在Unity中实现状态机设计模式
开发语言·unity·设计模式
csdn_aspnet32 分钟前
C# .NETCore json字符串压缩为一行
c#·json·.netcore
斯内科33 分钟前
C#验证拉马努金圆周率公式
c#·拉马努金圆周率
FuckPatience33 分钟前
C# BinarySearch 的返回值
开发语言·数据结构·c#
憨辰1 小时前
Unity I2多语言拆分方案【内存、包体⬇️】
unity·游戏引擎
27669582922 小时前
闪购商家端 mtgsig
java·python·c#·node·c·mtgsig·mtgsig1.2
张人玉13 小时前
技术开发文档:MES 系统与西门子 PLC 通信软件集成方案
https·c#·plc·mes系统·西门子s7
jtymyxmz13 小时前
《Unity Shader》12.5 Bloom 效果
unity·游戏引擎
jtymyxmz15 小时前
《Unity Shader》12.6 运动模糊
unity·游戏引擎
地球驾驶员16 小时前
NX二次开发C#----C#和C++的二次开发程序如何签名?
c#