How to Create a Twitch Chat Game with Unity
Learn to integrate the Twitch Chat API into your Unity game, so viewers can interact with the game during streaming. By Harrison Hutcheon.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
How to Create a Twitch Chat Game with Unity
45 mins
- Getting Started
- The Twitch Chat Script
- Reading in Chat Messsages From Twitch
- Parsing Chat Commands
- Parsing and Storing Commands
- The Game Manager
- Validating Commands
- Testing Commands
- Your Twitch Audience and You
- Audience vs Audience
- Audience vs Game
- Audience vs Streamer
- Common Design Challenges
- Delay
- Audience Interaction
- Streamer Interaction
- Where's the Fun?
- Exploring the Sample Scene
- Creating Commands
- Expanding the Vote Script
- Game Over and New Game Conditions
- Game Over Check
- Game Over Action
- New Game Action
- Revisiting the GameManager
- Using What You've Learned
- Where to Go From Here?
Using What You've Learned
You have the foundation and the know-how to create Twitch Chat games! Time to test those newfound skills.
There's another scene in the project called Golf. Use what you learned with Battle to turn it into a functional game!
Need help? Just open the spoiler below to find out how.
[spoiler title="Golf Game Requirements"]
Golf has the following requirements:
- A GameManager keeps track of players and can retrieve a player by username.
- Include a join command so audience members can join the game.
- When an audience member joins, spawn a golf ball for them in a random color with their twitch username displayed above the ball.
- Include commands to let a player:
- Set the direction of their ball.
- Set the power of their stroke.
- Launch their ball in the specified direction, at the specified power.
- A Game Over Check checks if all players have reached the hole.
- A Game Over Action disables commands and displays a scoreboard with the players listed from highest score to lowest score.
- A New Game Action resets the course and lets audience members submit commands.
See the following GIFs for an idea of what these features look like:
If you get stuck while working on Golf, check out the completed version in the Final assets to see some solutions.
[/spoiler]
Where to Go From Here?
Use the Download Materials button at the top and bottom of this tutorial to download both the starter and final projects. You can use the final project to compare with your own work.
In this tutorial you learned how to read messages from Twitch chat, and how to use them to interact with your game. Or two games if you did the bonus Golf game too!
Check out Introduction to Multiplayer Games With Unity and Photon to learn more about creating multiplayer games with Unity.
And while you are hanging out on Twitch, don't forget to follow Unity Tech for live streams of Made With Unity games and developer showcases. :]
I hope you enjoyed this article. If you have any questions or comments, please join the forum discussion below. See you in the next one!