Chat System Setup

This commit is contained in:
pelpanagiotis
2025-12-23 21:43:28 +02:00
parent 329b7d3183
commit 6262ec6b61
3474 changed files with 425014 additions and 28055 deletions

View File

@@ -0,0 +1,42 @@
using Mirror;
using System;
using UnityEngine;
using TMPro;
public class ChatBehaviour : NetworkBehaviour
{
[SerializeField] private TextMeshProUGUI chatText = null;
[SerializeField] private TMP_InputField inputField = null;
[SerializeField] private GameObject canvas = null;
public override void OnStartClient()
{
canvas.SetActive(true);
SpawnScript.OnMessage += HandleNewMessage;
}
private void OnDestroy()
{
SpawnScript.OnMessage -= HandleNewMessage;
}
private void HandleNewMessage(string message)
{
chatText.text += message;
}
[Client]
public void Send()
{
if (!authority)
{
Debug.LogWarning("Attempted to send chat without authority.");
}
if (string.IsNullOrWhiteSpace(inputField.text)) { return; }
NetworkClient.localPlayer
.GetComponent<SpawnScript>()
.CmdSendMessage(inputField.text);
inputField.text = string.Empty;
}
}