Unity Photon Chat | A Basic Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome back to a tutorial video of unity now in unity there is a multiplayer um like asset called photon and you might some of your old game devs might know about photon bolton is such as a multiplayer helping just streaming multiplayer asset which she can um do multiplayer right away and also yeah but there also are problems with photon remember photon chat photon chat is an essential plug-in for photon so you can chat to other people now in photon chat there is one problem they can't chat i mean no i mean they would or the tutorials are missing the tutorials they have missing scripts or missing episodes that we don't know where so i'm now here to complete a tutorial that you might you guys might happily enjoy and find out that it's interesting so you can join me into a another thing so let's do it okay so let's continue and well and so let's go back into a browser because i'm using a new suppose i'm using a new version of unity i can't go to the asset store so let's just go to the asset store let me see as it's stored as it stores its store you see yeah [Music] photon [Music] i'll fold on here and then we'll just scroll down and then we'll just find some of the photon fun too i hate the photo let me see the three assets let me see three assets and all you need to do is not this one now you have to download photon pawn 2 which is really not here i could not find here photon pan 2 which is free and you can just download this so let's just go back to our unity and since i've already downloaded it we'll just go to window package manager now just go to your my assets okay so we're in my form here i have a lot of patterns that i just got you just go to the uh one two three this is the photon if you need and import we'll just wait for that okay so open this here import package to import okay so we already does the installation now there would be a pawn setup and we have to um create the fun setup or the app id of this pun to create so we'll just go back pause the video okay so we're in this is just all my apps here and don't mind that because that's all just my tests so um check what version you need so we need this photon your name um i'll just call it youtube and the youtube um test yes just and then create we'll just wait for its creation and we don't want to see this so you can just take this copy this let's just go back to your unity and put this app id into here and set up project done you are done and you have now succeeded this is clearly here and now you might think that oh we need the photon chat we need to photon chat yet but wow we we don't need a photon chat the asset because we already have the app id chat full 2.2 has already the photo chat and you might be thinking oh no i tried combining the photocon 2 and photon chat but arrows broke up destroying my previous project so since i tested this on my new project new test project it works so we'll just have to get the i the the app id so let's go back to here let's create a new app photo chat youtube test the youtube test shot just wait for it to be created okay we'll just take the id which you'll see let's go back to unity and put it on there so it's already have connected we'll just take our fixed region to asia because i live in the philippines and that's asia so yeah and now let's create the script so let's create a folder um see script i'm going to create c-sharp script let's see um there we go and my unity will just compile scripts the process of compiling scripts okay so let's just open our chat manager let's just create a new window i'm using um a 30-day trial our um rider from jetbrains but you can also use visual studio and visual studio code as you do because i'm using which was to do code for by here so yeah so it's still loading its extensions so i'll just pause here okay so we're already in the loaded so let's set up this chat manager but i think i have to recommend first i think it will not work unless i will create a c-sharp spread for photon hold the pencil see you there so i have already done some editing on my on the project so now let's start off with the basics we have to import the classes so using photon which you actually need that chat and using photon dot that's what we need so we and there would be an error and why it is narrow because it doesn't have it all of its methods inside it so we have to implement the missing members so we'll just wait for it to turn on yeah we'll just click okay there we go so we have a lot of these but we'll just go on in a few weeks extensions just take off the throw new system not implement exception because that will give us an error on play or playing okay so there we are now let's create some functions so public void get connected there we go and then what what we actually need to do in get connected is let's get get out of the deep of the blog debug.log and we need to take out the string which is like [Music] connecting now before we do that we just have to create some prop variables i think so let's take a chat client chat client chat client we'll just make this private we'll not just use this [Music] and then create a public so since i'm using tmp pro on my um either on my online unity editor you can also use like this i'll just type using t and chrome text mesh where you can download it on the assets you know the package manager you also if you want to use the normal um ui just unity engine there we go so let's create a public called input field but i'm using tm text mesh pro so i'll just put tmp input field um let's just make this player name name and then public um for you those who you doesn't use tm pro you can just use text but since are you using tm pros um text mesh pro ugoi um connection state connect xion state another public same tmp input field now this input field would be the message area and another public public another text mesh pro text um uh the message area no none of the message area and finally we have to create two public game objects which i will explain later so most so this is the two public and now i'll get some strings okay so that's it now let's start the function so in void start application that one in background is equal to true then let's create an if statement for the photon network [Music] for the no if we don't have the id so i'll just copy some notes this is very long so see i'll just explain this so if the string is null or empty if the string is empty on the photo network app id chat then we just have to say um debug dot log error which means no reference equals there we go now part this here connection state dot text no not here we'll put it in okay so world chat is equal to well and now let's go to our get connected [Music] so let's print out a now yeah we have trying and chat client is equals to a new chat client and we need a script that has an i chat client listener so we'll just use this script this there then chat client. connect into the photo network photo network dot photon server settings that are settings that id chat and we have to put auto on authenticate nose application so photon network dot app version and then we have to take another um uh authentication values which is a new authentication values and we'll put in here we'll just um put some additional code here full time dot chat and then values and what we need to authenticate is the name of the player so the text of the player name no not player name dot text here we go so we just take the string of take the string that has been text on the name of the player name field so now we have already done gonna get connected let's go on to the next thing the update so the update again so if shot client service okay so now let's create the unconnected so let's take the so i'm just gonna put my intro panel on my panels my game i'm just that i do selective it's not not yet let's taste it chat client unsubscribe because we're gonna subscribe or go into like some some kind of joint joint thing so subscribe to the stream so a new string array that has that has word chat [Music] then chat client dot set online status set online status to check user status is what we need to make this to make the player online so now that's just the important things to connect to a chat field now let's create an event in which when the player subscribes to and there's an error let's see oh here it is okay i just need one more okay so now let's host the okay so unsubscribed we'll just as message [Music] message some things so let's make a for each loop reach in let's see what's the channels channels channel and now this that chat client called publish message just gonna publish a message which is chat which through the channel says string say says let's see join join okay let's just put comma there and let's make the status the player connection state that text is it close to it now no it's supposed to connect it it's supposed to [Music] okay so that's where we have now so let's create the get messages now if you really wanted to create a message then we have to make the message first how could we do that so we'll just need to go to a um a method here called on get messages this is where the message is i get the properties of a message so let's create a for loop for for loop here and then let's set this into no send this dot name now we'll take the message area that's where we need to put the message dot text is plus equals to we have to add a string so senders to put a array there and put the i inside and let's create a comma here so what so it will um describe what are they saying and then plus messages and then plus here so let's get the comma there you go so this is how you get a message and now the last thing is to create [Music] um how to send a message a method where we can send our messages so let's create a method here public void send message [Music] and then in the send message you could just a chat client but publish message from the world chat and then the message input now the message will put that text that's what we need for the string [Music] and you can also do um provide that undisconnected things by yourself you can just copy from this and you just um flip their properties like from connect to disconnect like that so since i already saved this let's go back to unity i created this ui for joining let's just create a photo all time manager just to test if this is really right so let's add a component another component let's see assets scripts network which is called a chat manager and there's a lot of stuff in here so let's just create a um uh the game objects the panels so let's create a that's it intro row and this is what the intro will be let's just put everything down to the intro right in true okay so let's create another panel ui panel uh we'll just disable the intro first let's resize our panel like this i have to set this and then in our panel let's wait we just have to set the cameras to the scale with the pixel size so i think you need to okay so i have to decrease this to one one okay so i have to flip my panel which is disable the intro click my panel okay so this is the message panel so message panel and let's create a button ui button yum send and move this down here and resize its shape and rotate well makes its text into set let's create a input field ui uh dismiss pro input field just draw this here it's near the sender now let's create a another text ui text this would be our area where we could text so i think most of you can create you devs can create sliders which i need to practice because i can create sliders of my own font size to 20 and create one more text ui text message pro up and then just center this there we go um uh just new text and new text will just remove this and just rename this text um area and then um status so there we go so let's see in our network we just need to connect our input field name so we'll just disable the message panel to see what you're looking at so just network we have already inputted the input field here this input field here then we'll just disable that and go to your message panel and you could your network you can take your connections that status for this status here and then in the area area where you need to text we'll just put it in the message message area now for the message input we'll just put the input field of this panel now i have the two things here the intro panel in the message panel i just put this so i can set activities two um panels so i'll just assign this message panel in the intro panel so we'll just make the intro the first thing we could see in join we'll just link up our button we'll just destroy this button here let's add a no button we'll put the network a chat manager get connected now in now in our message panel we have to assign the send button so we'll add a function click event and chat manager set message so now i have to put one more thing into this script now in on connected we have to disable disable the intro panel so intro panel the set active is equal to false then message panel dot set active is supposed to shoot so just save that okay let's just go to unity and just reload by itself so let's disable the intro panel now disable our message panel and go to our intro panel and let's if i failed this video would be a blown out so let's let me see how um 30 minutes because this is a very long thing let's try doing this and let's text we look fender my finger join connecting it's debugging connected oh i systematically i'm not sending anything let me try looking back at them um oh because the messages i forgot something in the messages i have to create an array with the eyes so that's why i forget don't forget this because this message is here is an array and you might be thinking this rd doesn't it doesn't um find errors of one of the arrays so you you have to be careful you have to put eyes in this so just go back come on this will always happen so let's type our name again join connecting there join let's text fender there so i said fender hello i said hello so let's go back so let's exit this and i'll build some uh build this project simple scene yes and then and i'll pause the video in my recording because this is gonna might take a long time so i'll just press this build here now later do you have a folder of build new folder let's see 2d 2d um tutorial and let's just select this folder and it will build and see you guys there when it's already built so it's already built and now we'll just enter the allow access because this is the game where internet should be accessed so just wait we'll text our text we will join and just join connected so let's see we know hello so if this not works i might be copyrighted or cancelled in this so let's go back to our beauty and then press the button and let's see if this works i don't know but it might work so then okay so let's see yeah it worked so let's send another message which is fander so it's send a message that's it that's for the um photog chat so just leave and he's already left so it's just gonna cancel yes and that's
Info
Channel: Fender's Simple Tutorials
Views: 1,197
Rating: undefined out of 5
Keywords: unity, photon
Id: gfQ4k1Rpc7U
Channel Id: undefined
Length: 35min 31sec (2131 seconds)
Published: Sat Dec 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.