Multiplayer Text CHAT | Unity Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 พ.ย. 2024

ความคิดเห็น • 9

  • @TheKr0ckeR
    @TheKr0ckeR หลายเดือนก่อน

    Thank you. I thought creating a string builder and adding the text to that would be more performant etc. Is there any spesific reason why you didnt prefer that way? BTW, for testing, I send playerName as "OwnerClientID" but they both seemed zero.

  • @reffer360
    @reffer360 8 หลายเดือนก่อน

    Thank you for this , can you do a follow up video to save and recall conversations?

  • @marianmartinco
    @marianmartinco 25 วันที่ผ่านมา

    Im using the newest version of unity and I was not able to open downloaded project. I tried to create new project and copy files here. It did open, but there was nothing of it. The scene was empty. Does anyone know how to make it work please?

  • @Its_Pogle
    @Its_Pogle  ปีที่แล้ว +2

    If you're looking for the basics, i'd strongly suggest CodeMonkey's tutorial before watching this!
    th-cam.com/video/3yuBOB3VrCk/w-d-xo.html&ab_channel=CodeMonkey

  • @florenscherry5238
    @florenscherry5238 6 หลายเดือนก่อน +1

    writes an error. I can’t insert your project from Github into Unity

  • @nikson12gg
    @nikson12gg หลายเดือนก่อน

    When enter is pressed:
    If chat is already open -> send message
    else if chat is closed -> only open chat
    Sadly this is what I wanted to do but it doesn't work, because "inputField.isFocused" isn't working properly I guess :((((
    This is my whole script btw:
    using TMPro;
    using UnityEngine;
    using System.Collections.Generic;
    using UnityEngine.EventSystems;
    public class ChatManager : MonoBehaviour
    {
    [SerializeField] TMP_InputField inputField;
    [SerializeField] TextMeshProUGUI placeholder;
    [SerializeField] Transform chatContent; // Parent of all texts (where texts should be instantiated)
    [SerializeField] Message chatTextPrefab; // Prefab that we will instantiate
    [SerializeField] int maxMessages = 50, characterLimit = 100;
    [SerializeField] List listOfMessages = new List();
    [field: SerializeField] public bool isChatOpen { get; private set; }
    string playerName;
    void Start()
    {
    inputField.characterLimit = characterLimit; // Maximum character input
    placeholder.text = $"Enter text... (Max: {characterLimit})";
    }
    public void SetPlayerName(string txt) { playerName = txt; } // Player object calls this method to set its name in the ChatManager
    void OnEnable() { EventManager.OnEveryFrame += PressingEnter; }
    void OnDisable() { EventManager.OnEveryFrame -= PressingEnter; }
    void PressingEnter()
    {
    isChatOpen = inputField.isFocused;
    if (Input.GetKeyDown(KeyCode.Return))
    {
    if (!isChatOpen) { inputField.Select(); return; } // Opens the chat box if it's not open; Restricts sending chat when the chat box is closed
    if (string.IsNullOrWhiteSpace(inputField.text)) return; // Restricts sending chat when input field is empty or whitespace (space, tab)
    if (listOfMessages.Count >= maxMessages) // If we've reached the max number of messages, destroy the oldest message from the content and list
    {
    Destroy(listOfMessages[0].gameObject);
    listOfMessages.RemoveAt(0);
    }
    Message newMessage = Instantiate(chatTextPrefab, chatContent); // Create a new message and make it a child of chatContent
    newMessage.textMeshPro.text = $"{playerName}: {inputField.text}"; // Assign the input text to the new message
    listOfMessages.Add(newMessage); // Add that message to the list as well (to be able to delete or hide it in the future)
    inputField.text = string.Empty; // Clear the input field to start fresh again
    }
    }
    }

  • @thundethunder1
    @thundethunder1 ปีที่แล้ว

    Nice, thanks for the video. Will be great to make this option available for every console, I mean with a screen keyboard adapted to the console with limited keys(withouth symbols, ctrl and shift for example). The other thing is that a lot of multiplayer games are teamplays, so somehow we need to know how to filter the sent message for allies or for everyone. How do developers filter some words on the chat and replace those words by ***?

    • @Its_Pogle
      @Its_Pogle  ปีที่แล้ว +3

      I'm not too sure how consoles or mobile adaptations would work, I don't have much experience developing on those devices. Although, I think it may be fully compatable and an onscreen keyboard would show up... don't hold me to it though.
      For team filtering, one way you can do it is passing through more variables when sending the chat message RPC's by passing through either a team number or string, followed by checking the users team to recieve the message. Therefore only recieving your own teams messages. Have a read of this Unity Sample! docs-multiplayer.unity3d.com/netcode/current/learn/bitesize/bitesize-invaders/
      To filter banned words, i'd pass it the message through a method which takes in the message string when recieving it and checking each word if it's equal to a word on your banned word list? This could be the same for localization possibly..?
      There are so many ways you could do it, i'm just suggesting one way, it's probably not the most efficient. Hope that made sense, thanks for the support. :)

    • @jaehyun88309
      @jaehyun88309 2 หลายเดือนก่อน

      ig something like this:
      if message contains [banned words], send "***" instead