Skip to content

A Unity tool that will allow you to easily implement Twitch chat commands into your game!

License

Notifications You must be signed in to change notification settings

danqzq/unity-twitch-chat-interactions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Twitch Chat Interactions

Downloads Latest Version

A Unity tool that will allow you to easily implement Twitch chat commands into your game!

Simple & Straightforward

Unity Twitch Chat Interactions focuses on ease of integration for the developer.

Command Example

[TwitchCommand("join", "j")]
public void Join(string playerName, int skin)
{
    // Spawn player instance for Twitch viewer with specified name and skin
}

In this example, every time a viewer types !join <player-name>, the Join method is executed automatically provided with the viewer's input for the playerName and skin arguments.

Adding new commands is as simple as adding TwitchCommand attributes on any script* attached to an active GameObject in a scene.

Note

Scripts containing TwitchCommand methods must inherit from TwitchMonoBehaviour!

Auth Setup Requirement

You must register your game on Twitch. Follow this link for guidance:

https://dev.twitch.tv/docs/authentication/register-app

Upon registration, your game will be assigned a Twitch Client ID, which you must copy and paste into the Game Twitch Client ID field in the Settings tab of the tool's editor window, accessible through the toolbar in Unity (Dan's Tools > Twitch Commands).

Before any streamer can download your game and immediately have their chat interacting, they must authorize with your game on Twitch.

Assets/TwitchIntegrationDemo/Scenes contains the Authentication scene, from which you can copy the prompt/logic into your game's scenes.

Follow the YouTube video guide below on how to set up the tool completely:

YouTube Tutorial

More Usage Examples

Viewer Information

Access viewer info by setting the first parameter as TwitchUser user:

[TwitchCommand("echo")]
public void Echo(TwitchUser user, string msg)
{
    Debug.Log($"{user.displayname} says {msg}");
}

Command Modes

Currently there are two modes for command behaviour:

  • Limitless
  • Cooldown (commands enter a specified cooldown upon execution)

You can customize this in the Settings menu of the tool's editor window, accessible through the toolbar in Unity.

Events

You can listen to C# events provided to perform custom actions:

public static class TwitchManager
{
  ...
  // Gets triggered when the Twitch client connects to the chat.
  public static event System.Action OnTwitchClientJoinedChat;
  
  // Gets triggered when a message is received from the Twitch chat.
  public static event System.Action<TwitchUser, string> OnTwitchMessageReceived;
  
  // Gets triggered when a command is received from the Twitch chat.
  public static event System.Action<TwitchUser, TwitchCommand> OnTwitchCommandReceived;
  
  // Gets triggered when the Twitch client fails to connect to the chat.
  public static event System.Action OnTwitchClientFailedToConnect;
  ...
}

Send Messages

To send messages from the Twitch client, make use of this function:

TwitchManager.SendChatMessage("Your message here");

How to Download?

It is recommended that you download the latest Unity Package provided in Releases.

Optionally, you can clone this repository and copy contents of Assets into your Unity project's Assets folder.

Demos

See Assets/TwitchIntegrationDemo for demo scenes:

  • Twitch authentication
  • Ready-to-use prefabs (e.g chat box, command display, etc).

Games using Unity Twitch Chat Interactions

License

This tool is under the MIT License

Feedback

Don't hesitate to reach out to me for any questions, feedback or concerns. Shoot me an email!

Contributing

Before you start adding something of your own, read the Contribution Guidelines

Enjoy building cool stuff,
Dan

About

A Unity tool that will allow you to easily implement Twitch chat commands into your game!

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages