今天我又又又来发Mirror啦,有需要更多代码的可以找我,文章如果有错,欢迎大佬改正。
常用代码
1.第一人称角色移动代码:
这个其实很简单,在原来移动的基础上加上if (!isLocalPlayer) return;就行了,然后再绑定一下摄像机
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Playercode : NetworkBehaviour {
public float speed = 5f;
//cam
public Camera cam;
// Use this for initialization
public override void OnStartLocalPlayer()
{
base.OnStartLocalPlayer();;
//Cursor.visible = false;
//Cursor.lockState = CursorLockMode.Locked;
cam.gameObject.SetActive(true);
}
private void FixedUpdate()
{
if (!isLocalPlayer) return;
Move();
MouseLook();
}
// Update is called once per frame
void Update () {
if (!isLocalPlayer) return;
if (Input.Get