Unity第一人称漫游简单好用(和cf一样)

wasd移动 鼠标旋转方向  空格跳跃  ctrl蹲

先新建空物体player 绑定 characterController和 FirstPersonController组件 

然后相机为子物体 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class FirstPersonController : MonoBehaviour
{
    public float speed = 5.0f; // 移动速度
    public float mouseSensitivity = 2.0f; // 鼠标灵敏度
    public float jumpSpeed = 8.0f; // 跳跃速度
    public float gravity = 20.0f; // 重力

    private CharacterController characterController;
    private Vector3 moveDirection = Vector3.zero;
    private float rotationX = 0.0f;
    private float rotationY = 0.0f;
    private Camera playerCamera;

    public float crouchHeight = 0.5f; // 蹲下高度
    public float normalHeight = 2.0f; // 正常高度
    public float crouchSpeed = 2.5f; // 蹲下时的移动速度

    private bool isCrouching = false;

    void Start()
    {
        characterController = GetComponent<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值