So i have this code for my spaceship and its giving me error on line 31 wheres there an is local player if statement,Here’s the code
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 float shakeAmount;
public ParticleSystem particle;
private ParticleSystem pscom;
public GameObject spaceship;
private FOUDemo fou;
void Start()
{
fou = spaceship.GetComponent<FOUDemo>();
pscom = particle.GetComponent<ParticleSystem>();
}
void Update()
{
if (isLocalPlayer) //error here
{
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;
fou.velocity = 500;
}
if (Input.GetKey("w"))
{
fou.thrust = fou.thrust + 1;
}
if (Input.GetKey("s"))
{
fou.thrust = fou.thrust - 1;
}
}
}
}
The error is in mirror islocal player checker and it was called by this
The error is NullReferenceException: Object reference not set to an instance of an object
when i already put a network identity and a network transform on it
