my chat is not working in photon unity

my problem is that I am doing a Chat but when I start writing nothing comes out and I cannot move and it happens when there are two or more in the room, when I am alone it works perfectly.
This is the code for the chat:
public static ChatManager Instance;

    bool isChatting = false;
    string chatInput = "";

    PhotonView PV;

    [System.Serializable]
    public class ChatMessage
    {
        public string sender = "";
        public string message = "";
        public float timer = 0;
    }

    List<ChatMessage> chatMessages = new List<ChatMessage>();
    
    void Awake()
    {
        PV = GetComponent<PhotonView>();
        Instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
       
    }



    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.T) && !isChatting)
        {
            isChatting = true;
            chatInput = "";
        }

        //Hide messages after timer is expired
        for (int i = 0; i < chatMessages.Count; i++)
        {
            if (chatMessages[i].timer > 0)
            {
                chatMessages[i].timer -= Time.deltaTime;
            }
        }

       
    }

    void OnGUI()
    {
        
        if (isChatting)
        {
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
            {
                isChatting = false;
                if (chatInput.Replace(" ", "") != "")
                {
                    //Send message
                    PV.RPC("SendChat", RpcTarget.AllBuffered, PhotonNetwork.LocalPlayer, chatInput);
                }


                chatInput = "";
            }

            GUI.SetNextControlName("ChatField");
            GUI.Label(new Rect(5, Screen.height - 25, 200, 25), "Say:");
            GUIStyle inputStyle = GUI.skin.GetStyle("box");
            inputStyle.alignment = TextAnchor.MiddleLeft;
            chatInput = GUI.TextField(new Rect(10 + 25, Screen.height - 22, 150, 16), chatInput, 50, inputStyle);

            

            GUI.FocusControl("ChatField");
        }

        //Show messages
        for (int i = 0; i < chatMessages.Count; i++)
        {
            if (chatMessages[i].timer > 0 || isChatting)
            {
                GUI.color = Color.green;
                GUI.Label(new Rect(5, Screen.height - 50 - 25 * i, 500, 25), chatMessages[i].sender + ": " + chatMessages[i].message);
            }
        }
    }

    [PunRPC]
    void SendChat(Player sender, string message)
    {
        ChatMessage m = new ChatMessage();
        m.sender = sender.NickName;
        m.message = message;
        m.timer = 15.0f;

        chatMessages.Insert(0, m);
        if (chatMessages.Count > 8)
        {
            chatMessages.RemoveAt(chatMessages.Count - 1);
        }
    }

Best Answer

  • TobiasTobias admin
    Accepted Answer
    We do not debug code. We can help with the concepts of networking.

    An error description like this will not work well in most forums. You did not point out what happens, what you verified, etc. You need to learn a bit about debugging your errors yourself, before you can ask such a question properly.

    Try adding Debug.Log to methods you want to check if they are being called. Make sure they are being called.

Answers

  • TobiasTobias admin
    Accepted Answer
    We do not debug code. We can help with the concepts of networking.

    An error description like this will not work well in most forums. You did not point out what happens, what you verified, etc. You need to learn a bit about debugging your errors yourself, before you can ask such a question properly.

    Try adding Debug.Log to methods you want to check if they are being called. Make sure they are being called.
  • Hey Tobias thanks for answering but I already solved the problem, I don't know how I solved it but out of nowhere he let me get away without any error
  • TobiasTobias admin
    Ok, glad you're no longer blocked.
Sign In or Register to comment.