Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Photonnetwork does not contain a definition for 'playerName'

Discussion in 'Getting Started' started by TinySpoonsRGr8, Sep 24, 2023.

  1. TinySpoonsRGr8

    TinySpoonsRGr8

    Joined:
    Nov 19, 2020
    Posts:
    1
    I am very new to coding and I am currently following this tutorial:

    The errors I am having are:
    upload_2023-9-24_10-15-57.png

    This is my code:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using Photon.Realtime;
    using UnityEngine.UI;

    public class MenuController : MonoBehaviour
    {
    [SerializeField] private string VersioName = "0.1";
    [SerializeField] private GameObject UsernameMenu;
    [SerializeField] private GameObject ConnectPanel;

    [SerializeField] private TMPro.TMP_InputField UsernameInput;
    [SerializeField] private TMPro.TMP_InputField CreateGameInput;
    [SerializeField] private TMPro.TMP_InputField JoinGameInput;

    [SerializeField] private GameObject StartButton;
    private void Awake()
    {
    PhotonNetwork.ConnectUsingSettings();
    }

    private void OnConnectedToMaster()
    {
    PhotonNetwork.JoinLobby(TypedLobby.Default);
    Debug.Log("Connected");
    }

    public void ChangeUsernameInput()
    {
    if (UsernameInput.text.Length >= 3)
    {
    StartButton.SetActive(true);
    }
    else
    {
    StartButton.SetActive(false);
    }
    }

    public void SetUserName()
    {
    UsernameMenu.SetActive(false);
    PhotonNetwork.playerName = UsernameInput.text;
    }

    public void CreateGame()
    {
    PhotonNetwork.CreateRoom(CreateGameInput.text, new RoomOptions() { maxPlayers = 3 }, null);
    }
    }
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,105
    This is not related to 2D so please don't use this forum for anything other than 2D related posts.

    I'll move your post to the "Getting Started" sub-forum for you though.

    You should probably refer to the documentation for the PhotonNetwork, maybe the tutorial is outdated?

    Note, here's how to post code on the forums: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Thanks.
     
    TinySpoonsRGr8 likes this.