Skip to content

Instantly share code, notes, and snippets.

Last active May 2, 2022 01:59
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// We need to add the Unity.UI library to access UI elements.
using UnityEngine.UI;
/// <summary>
/// This class is in charge of
/// </summary>
public class UIController : MonoBehaviour
// UI elements
public Button ButtonSendMessage;
public InputField InputField;
public Text MessageDisplay;
// Use this for initialization
void Start()
// Subscribe our 'SendMessageUpdateRequest' method to ButtonSendMessage onClick events
// Therefore: everytime we click on the button, 'SendMessageUpdateRequest' will be called
// Also, subscribe our 'UpdateMessage' method to listen for OnMessageUpdateRequest calls
EventController.OnMessageUpdateRequest += UpdateMessage;
void SendMessageUpdateRequest()
// Store the input field's text into a string
string message = InputField.text;
// Call the 'Event_OnMessageUpdateRequest' static method from the EventController class
void UpdateMessage(string _message)
// Print the message
Debug.LogFormat("-- UIController // Updating message: {0}", _message);
// Replace the current message with the contents of the _message string
MessageDisplay.text = _message;
// Reset the text of our input field
InputField.text = "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment