i have this code for the player movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerMovement : MonoBehaviour
{
public MovementJoystick movementJoystick;
public float playerSpeed;
private Rigidbody2D rb;
public Camera m_camera;
PhotonView view;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
view = GetComponent<PhotonView>();
movementJoystick = GameObject.FindGameObjectWithTag("JoyStick").GetComponent<MovementJoystick>();
if(!view.IsMine){
m_camera.enabled = false;
}
}
// Update is called once per frame
void FixedUpdate()
{
if(view.IsMine){
if(movementJoystick.joystickVec.y != 0)
{
rb.velocity = new Vector2(movementJoystick.joystickVec.x * playerSpeed, movementJoystick.joystickVec.y * playerSpeed);
}
else
{
rb.velocity = Vector2.zero;
}
}
}
}
and the pause:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PauseManager : MonoBehaviourPunCallbacks
{
public GameObject pauseMenu;
public bool isPaused;
// Start is called before the first frame update
void Start()
{
isPaused = false;
pauseMenu.SetActive(false);
}
// Update is called once per frame
void Update()
{
}
public void PauseButton()
{
PauseGame();
}
public void PauseGame(){
pauseMenu.SetActive(true);
isPaused = true;
}
public void ResumeGame(){
pauseMenu.SetActive(false);
isPaused = false;
}
public void QuitGame(){
PhotonNetwork.LeaveRoom();
PhotonNetwork.AutomaticallySyncScene = false;
SceneManager.LoadScene("Lobby");
pauseMenu.SetActive(false);
}
void OnApplicationPause ( bool pause )
{
if(pause){
PauseGame();
}
}
}
but when I go back to the lobby and create a new lobby only the first player gets in and I get the error
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.LateUpdate () (at Assets/Scripts/PlayerMovement.cs:32)