2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Youtube stream chat box Unity plugin

Last updated at Posted at 2021-02-17

ezgif.com-gif-maker.gif
I like to watch Vtuber since Hololive EN pop up.
But I feel something wrong when watching there LIVE show(I'm also a photographer too).
There is no audience under the stage, that make the LIVE show looks deserted.
So I have an idea, why don't we plugin the chat box from Youtube to the LIVE show?
Let' start the project!
#Acknowledgements
This code will use part of @MCK9595 's code.
If you want to learn more about Youtube API, here is his article: https://qiita.com/MCK9595/items/fdbd543ff938febcd136
#How it work
流程02.png
There will be three part in this code.
I have try to write all the code in Unity before, but YouTube Live Streaming API crash sometime, so I build a server to get the chat message, let Unity can run perfectly even when the API was crash.
Now let me teach you how to set up it step by step!
In this article I'm only teaching how to use my code, I will explain how I wrote it if there is someone interesting.

#Get chat message on YouTube
First you have to get your own Youtube API key.
Here is how to get it.(by @MCK9595)
After you get the key.
Here is my project file:
https://drive.google.com/drive/folders/1efYWB6uXzHWPgIa8q-jKh4uJenDltmdz?usp=sharing
image.png
Use Visual Studio 2019 to open it, after you download all the file.
image.png
Open[Program.cs] <--Thanks for @MCK9595 's code again.
image.png
Put your API key in line 21.
image.png
Copy the URL from the stream.
image.png
Past it in line 23.
image.png
And delete [https://youtu.be/] in the URL.
ex:

https://youtu.be/9Ur1dFz76S0 ----> 9Ur1dFz76S0

image.png
Run the server, than you can see the chat is in your server.
Next we set up the UDP server, send the chat into Unity.
#Set up the UDP IP & port
image.png
You can find the IP set up and the port set up in line 48.
In this project, I run server and Unity in the same PC, so it set up on the local host(127.0.0.1).
###UPD port###
https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
You can check the port number on this page, make sure the port is not busy.
#Unity side
https://drive.google.com/drive/folders/1wmvLosYNxCDCru0ex_pcPv4bxAhq_c2N?usp=sharing
image.png
Crate the [Text] object where want to show those chat.
Make sure you change the Tag to [Text].
text.png
image.png
Crate a [Empty object] and put the code in it, I put tree in it, but you can put as much as you want.
###How it work###
unitySide.png
#How to add new
image.png
Copy and past an other Server project file.
image.png
Put a new [AutoUDPReadLIVEMessage] in the empty object.
image.png
image.png
Make sure the Server is in the same port with [AutoUDPReadLIVEMessage] code in Unity.
image.png
Crate new Text, I crate six of it.
image.pngimage.png
Change all the start and end number in [AutoUDPReadLIVEMessage] script.
unitySide02.png
That's it!

#Tip
###Server crash###
1.Check you API key is open.(Sometime the key will close, prepare as more as you can)
2.Check the stream is still playing.
###Unity can't get the message###
1.Check your port is same with the server side.
2.You have to run the server and the Unity in the same PC.

##Have fun

2
1
10

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?