Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

problems with the script

Discussion in 'Getting Started' started by koerog09, Jan 12, 2023.

  1. koerog09

    koerog09

    Joined:
    Jan 7, 2023
    Posts:
    2
    I do not know what data is needed for TMP_Input, please help, here is my code

    using UnityEngine.UI;
    using Photon.Pun;
    using Photon.Realtime;
    using UnityEngine;

    public class MainMenu : MonoBehaviourPunCallbacks
    {
    public TMP_InputField InputFieldNameRoom;
    public GameObject ErrorPanel;
    public void CreatRoom()
    {
    if (TMP_InputFieldNameRoom.text.Length > 5)
    {
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = 6;
    PhotonNetwork.CreateRoom(InputFieldNameRoom.text, roomOptions);
    }
    else ErrorPanel.SetActive(true);
    }
    public void JoinRoom()
    {
    if (TMP_InputFieldNameRoom.text.Length > 5) PhotonNetwork.JoinRoom(InputFieldNameRoom.text);
    else ErrorPanel.SetActive(true);
    }
    public override void OnJoinedRoom()
    {
    PhotonNetwork.LoadLevel("Game");
    }
    }
     
    Last edited: Jan 12, 2023
  2. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Welcome to the forum, I can't really help with the script, except to advise you to use CODE tags when displaying C# code on here, and when you're typing in code by hand, watch your spelling and grammar, it's VERY sensitive.
     
  3. koerog09

    koerog09

    Joined:
    Jan 7, 2023
    Posts:
    2
    ok thanks for the advice
     
  4. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    616
    The code is "all over the map". We don't what problem you are experiencing but it isn't related to TMP_InputField. This doesn't compile correct? And if you view it from Visual Studio there are several items marked in red?

    First rule before writing any code is determine what you will be trying to do. Do this in pseudocode in your spoken language. Then you translate what you have decided to do into C#.

    CreatRoom is an odd name for a method. InputFieldNameRoom is defined but you reference something named TMP_InputFieldNameRoom which doesn't appear to exist. You check to see if the length is greater than 5 (the length of a room name isn't nearly as important as it being valid, etc., etc.

    Photon has a set of rules you must adhere to to connect to their server, to join the lobby and to create and join a room. It doesn't appear that you are following those rules. If I might suggest you can typically get more Photon and Pun-related support from their Discord. Still you should check their docs and work thru and example or two until the basics make sense.