i use mirror to create a multiplayer game.So Once i press host+client and connect a client to it , The first client will be locked to a view,Input not responding ans such,Is there any fix?The script is basic camera rotation with movement and islocal player check.Every time a new client join,The client that connect before will lose control.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class CameraLook : NetworkBehaviour
{
private Vector3 rotation;
public float lookSpeed;
public GameObject GameObjectTransform;
public GameObject Camera;
public float lookXLimit = 60.0f;
public float ZoomAmount = 0;
public float MaxToClamp = 100;
public float ROTSpeed = 10;
public Transform camTransform;
public ParticleSystem particle;
public ParticleSystem Shock;
private ParticleSystem pscom;
private ParticleSystem Shockcom;
public GameObject spaceship;
private FOUDemo fou;
void Start()
{
fou = spaceship.GetComponent<FOUDemo>();
pscom = particle.GetComponent<ParticleSystem>();
Shockcom = Shock.GetComponent<ParticleSystem>();
}
void Update()
{
if (isLocalPlayer == false) return;
if (Input.GetMouseButton(1))
{
rotation.y += Input.GetAxis("Mouse X") * lookSpeed;
rotation.x += -Input.GetAxis("Mouse Y") * lookSpeed;
rotation.x = Mathf.Clamp(rotation.x, -lookXLimit, lookXLimit);
GameObjectTransform.transform.localRotation = Quaternion.Euler(rotation.x, rotation.y, 0);
}
ZoomAmount += Input.GetAxis("Mouse ScrollWheel");
ZoomAmount = Mathf.Clamp(ZoomAmount, -MaxToClamp, MaxToClamp);
var translate = Mathf.Min(Mathf.Abs(Input.GetAxis("Mouse ScrollWheel")), MaxToClamp - Mathf.Abs(ZoomAmount));
Camera.transform.Translate(0, 0, translate * ROTSpeed * Mathf.Sign(Input.GetAxis("Mouse ScrollWheel")));
if (Input.GetKey("space"))
{
var emission = pscom.emission;
emission.enabled = true;
fou.velocity = 5000;
}
if (Input.GetKeyUp("space"))
{
var emission = pscom.emission;
emission.enabled = false;
var emission2 = Shockcom.emission;
emission2.enabled = true;
Shockcom.Stop();
Shockcom.Play();
fou.velocity = 500;
}
if (Input.GetKey("w"))
{
fou.thrust = fou.thrust + 1;
}
if (Input.GetKey("s"))
{
fou.thrust = fou.thrust - 1;
}
}
}