I was trying to add Nicknames to my game. Everything is okay, but when im entering playmode, the player isn't moving, and in Console Unity sends me this message:
object reference not set to an instance of an object
HERE'S SCRIPT FOR PLAYER:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
public class Player : MonoBehaviourPun
{
private float X, Y;
public float speed;
private bool isf;
PhotonView view;
private Joystick joystick;
private Rigidbody2D rb;
public Text textName;
// Start is called before the first frame update
void Start()
{
textName.text = view.Owner.NickName;
rb = GetComponent<Rigidbody2D>();
view = GetComponent<PhotonView>();
joystick = GameObject.FindGameObjectWithTag("Joystick").GetComponent<Joystick>();
}
// Update is called once per frame
void Update()
{
X = joystick.Horizontal * speed;
Y = joystick.Vertical * speed;
if (view.IsMine)
{
rb.velocity = new Vector2(X, Y);
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 moveAmount = moveInput.normalized * speed * Time.deltaTime;
transform.position += (Vector3)moveAmount;
}
}
}
HERE'S SCRIPT FOR MENU MANAGER:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
public class MenuManager : MonoBehaviourPunCallbacks
{
public InputField createInput;
public InputField joinInput;
public InputField inputName;
public void CreateRoom()
{
RoomOptions roomOptions = new RoomOptions();
roomOptions.MaxPlayers = 4;
PhotonNetwork.CreateRoom(createInput.text, roomOptions);
}
public void JoinRoom()
{
PhotonNetwork.JoinRoom(joinInput.text);
}
public override void OnJoinedRoom()
{
PhotonNetwork.LoadLevel("Game");
}
public void SaveName()
{
PlayerPrefs.SetString("name", inputName.text);
PhotonNetwork.NickName = inputName.text;
}
void Start()
{
inputName.text = PlayerPrefs.GetString("name");
PhotonNetwork.NickName = inputName.text;
}
}
I was expecting to see nicknames in my game. As a result, my player is not moving, and there is an error in the console.