> For the complete documentation index, see [llms.txt](https://runninghorse.gitbook.io/gdnet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://runninghorse.gitbook.io/gdnet/jin-jie/shi-yong-cinemachine-xiang-ji.md).

# 使用Unity新的第三人称控制器

一、安装Unity新的第三人称控制器

&#x20;有关Unity新的第三人称控制器的知识网上已经很多了，这里就不单独介绍了，也可以去B站看我的视频

<https://www.bilibili.com/video/BV1Zb4y1C7Si>

{% embed url="<https://www.bilibili.com/video/BV1Zb4y1C7Si>" %}

![](/files/-Mi0YwWblwtMZlQTwor7)

由于Unity新的第三人称控制器默认使用的是新的输入系统。为了兼容前面的教程，我们需要改为新旧两种输入系统同时使用。

![](/files/-MiAeW0gGuAfCWW4dT09)

二、删除Main Camera，将第三人称控制器中的MainCamera、PlayerCapsule、PlayerFollowCamera拖入Hierarchy窗口。

![](/files/-Mi6fLpXCS3ZP-l2mrjD)

![](/files/-Mi6faY4MQl29kT1U8Ou)

三、将Hierarchy窗口的PlayerCapsule改名为Player3，并且Unpack。

![](/files/-Mi6lj3PBj7A9pe6lOde)

将Inspector窗口的CharacterControlller、ThirdPersonController、PlayerInput的勾取消；加入TransformComponent

![](/files/-Mi6lzChDa4wMzvfVwMC)

将Player3拖入Project，成为Prefab。删除Hierarchy窗口的Player3.

![](/files/-Mi6uyrNiG-b-7r22Q9E)

将Player3这个Prefab分别拖入GameManager和NetworkManager

![](/files/-Mi6vPVNmBteERthui40)

![](/files/-Mi6ves9RT86BLxKAk2h)

再修改Player3这个Prefab，SynaMode改为Local，Index改为2，FixedSync勾选。

![](/files/-Mi6wgUaSuO4JTNtnubM)

四、修改GameManager.cs

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Net.Component;
using Cinemachine;
using UnityEngine.InputSystem;
using StarterAssets;

public class GameManager : MonoBehaviour
{
    public List<GameObject> PlayerPrefabs;

    private void Start()
    {
        ClientManager.Instance.client.OnConnectedHandle += Connected;
    }

    private void Connected()
    {
        //生成 Index=2的模型Player
        SpawnPlayer(2, Vector3.zero, Quaternion.identity);
    }

    public void SpawnPlayer(int _modelIndex, Vector3 position, Quaternion rotation)
    {
        NetworkTransformBase.Identity = ClientManager.UID;

        GameObject _player = Instantiate(PlayerPrefabs[_modelIndex], position, rotation);

        if (_modelIndex == 2) //使用第三人称控制器
        {
            _player.GetComponent<CharacterController>().enabled = true;
            _player.GetComponent<ThirdPersonController>().enabled = true;
            _player.GetComponent<PlayerInput>().enabled = true;

            GameObject.Find("PlayerFollowCamera").GetComponent<CinemachineVirtualCamera>().Follow =
                _player.transform.Find("PlayerCameraRoot").transform;
        }
        else
        {
            _player.GetComponent<PlayerController>().enabled = true;
        }
    }
}
```

至此，我们完成了在GDNet中使用Unity新的第三人称控制器。

![](/files/-Mi9HLTBUr5wc2p39KtV)
