This is a handmade library to connect Unity with Twich Chat Api, easy to use and easy to understand
This tutorial was made for Hector Pulido for his youtube channel
https://www.youtube.com/c/HectorAndresPulidoPalmar
And his Twitch Channel
https://goo.gl/otWsda (Hector_Pulido_)
- Commands support
- Custom twitch events support
- Sub, resub, bits, raid, etc
- On init event, Disconnect event, Etc
- Current chatter list
- More Examples of use
- First of anything make sure you have a twitch acount
- You will need a OAUTH Key from Twitch https://twitchapps.com/tmi/
- Just Code what do you need just like this
- List of tags https://dev.twitch.tv/docs/irc/tags/
This example switch a cube rotation depending of the Twitch chat and the commands !stop and !continue
using TwitchBot;
using CielaSpike; //You have to import this two namespaces
public class ConnectTest : UnityBot //You have to inherit from UnityBot
{
public Transform cube;
public bool rotating;
public int maxRetry;
void Start()
{
commands = new Dictionary<string, BotCommand>();
//Command bots has 2 Arguments, the first one is an array of arguments
//The other one it's the message it self
commands.Add("!stop", new BotCommand((string[] args, Message message) =>
{
Debug.Log($"{message.username} ha ejecutado el comando !stop");
rotating = false;
}));
commands.Add("!continue", new BotCommand((string[] args, Message message) =>
{
Debug.Log($"{message.username} ha ejecutado el comando !continue");
if (args.Length > 1)
{
Debug.Log($"Y el primer comando es {args[1]}");
}
rotating = true;
}));
whenNewMessage += (Message message) =>
{
Debug.Log($"{message.username}: {message.message}");
};
whenNewSystemMessage += (string message) =>
{
Debug.Log($"System: {message}");
};
whenDisconnect += () =>
{
Debug.Log("Desconexion");
};
whenStart += () =>
{
Debug.Log("Conexion");
};
whenNewChater += (string username) =>
{
Debug.Log($"{username}, bienvenido al stream!");
SendMessageToChat($"{username}, bienvenido al stream!");
};
whenSub += (Message message) =>
{
Debug.Log($"{message.username} Muchas gracias por esa subscripcion");
SendMessageToChat($"{message.username} Muchas gracias por esa subscripcion");
};
// You have to initializate the bot with this command
this.StartCoroutineAsync(StartConnection(maxRetry));
}
private void Update()
{
// Game logic
if(rotating)
cube.localEulerAngles += new Vector3(0, 0, 360) * Time.deltaTime;
}
}
- This project uses Thread Ninja
- This project uses Twitch Api
- Everything else is 100% handcrafted for me and MIT license