How To Make A Pick Up Game - VRChat Udon 2023

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's it going today we're going to be making a simple pickup game where when you collect all the cubes it triggers an event such as opening the door to a secret room and we're going to go over making a UI counter that keeps track of the number of Cubes you collected I'll be honest with you today's lesson is going to be a little bit code intensive but don't worry you and I are going to walk through it together and just a side note we're going to make the game completely local that means when anyone enters the world they're going to get a completely separate and private instance of the game for themselves so without further Ado let's get to it go to the top left of the hierarchy and select the plus icon go to UI canvas rename your canvas to cube count canvas SL logic select your canvas go to its inspector and then go to the canvas module change the render mode from screen space overlay to World space then under canvas scaler change the dynamic pixels to five because the default size for canvases in unity is freaking huge we're going to have to adjust the size so under width change it to 100 then change the height to 50 go down to scale and change the scale to 01 by 01 5.01 select your canvas and then hit contrl shift F this will bring the canvas right in front of you change the rotation to zero 0 0 lastly let's add a udon Behavior component to hold the logic for our canvas go to add component udon Behavior now that we've completed our main canvas let's set some text select your canvas rightclick go to UI text rename that text to collected cubes text select the text again and change the width to 50 then change the height to 50 as well go down to the text module and change the main text to zero then change the font style from normal to bold and under font size set it from 14 to 20 under paragraph change the alignment to far right and Center then change the color to white grab the canvas and drag it over to where it takes up the left part of the main canvas then select it and duplicate the text canvas rename the duplicate to total cubes text drag that canvas to where it occupies the right side of the main canvas then under text type in slash2 because we're only going to be making two pickup cubes under alignment change it to far left and now we've completed our Cube counter let's start working on making our pickup cubes I'm going to be using Pro Builder but feel free to use the inbuilt 3D modeler that comes with unity already Select probuilder Plus icon Cube and build select the cube and rename it to pickup Cube number one go to the cubes inspector and deselect static then under scale set it to 0.1 5.1 5.1 then go to its box collider and select is trigger next let's add a udon Behavior component select add component and search up udon Behavior select pickup Cube number one again and duplicate it rename the duplicate to pickup Cube number two now that we've completed both our pickup cubes as well as our counter let's start working on the udon graph scripts first go to assets then rightclick create VR chat udon udon graph program asset rename the script to pickup Cube logic then open Udon graph once you're in udon graph go to the variables Tab and select the plus icon then search up udon Behavior rename the udon Behavior variable to collected CU logic hit the arrow and change it to public then hit the plus icon again and search up game object rename the game object variable to pick up Cube then hit the arrow again and change it to public hit compile and drag both your variables onto your graph next hit the space bar and search up Event Event interact then hit the space bar again and search up udon Behavior under udon Behavior select send custom event next hit the space bar and search up game object and under game object select set active and lastly hit the space bar again and search up string under string select construct string once all your notes are connected go to string and name it to cube collected and that will be the first half of the udon scripts now that we've completed the first half of the udon logic let's start working on the second half select assets right click trade VR chat udon udon graph program asset rename the new script to collected Cube logic then open Udon graph once you're in udon graph go to the variables tab because this is going to be a larger script let's make the variables first go to the plus icon and create a integer variable rename the inte your variable to cubes collected then plus icon again and create another integer variable rename the second variable to Total cubes needed then plus icon and search up text rename the text variable to collected cubes display and lastly plus icon and create a game object variable rename that game object variable to secret door then set all your variables to public and hit compile now that our variables are complete let's start working on the udon graph I went ahead and separated the graph into four separate parts using groups if you want to create a group for yourself just right click and select create group once it pop poates you can rename it to whatever you like and if you no longer want the group just select it and press delete so let's begin for group number one create a custom event node hit the space bar and search up event then drop the custom event into the group Next we're going to copy and paste the string name from the pickup Cube logic script script into the custom event node select your script and open un on graft go to it string and copy the string name then go back to the collected Cube logic script go to the custom event node and paste it in bear in mind that string names are typically case and spacing sensitive so copying and pasting the string name typically removes the potential for a mistake next select the Cube's collected variable hold down control and drag the variable onto the script under the cubes collected variable select send change next hit the space bar and search up integer under integer select the addition node in the addition node change the lower zero to a one then select the cubes collected variable and drag it onto your script plug the variable into the top half of the addition node and that's it for group number one for group number two hit the space bar and search up UI text under UI text search for set text connect the text node to the set cubes collected node then hit the space bar and search up integer under integer search for two string connect the string to the value slot in the text node then connect the instance to the integer slot in the cubes collected node lastly grab the collected cubes display text variable and drag it onto your graph connect the text to the instance slot in the text node highlight your nodes and drop them into group number two and that's it for group number two for group number three hit the space bar and search a branch then hit the space bar again and search up integer under integer search up equals connect the equals bll to the branch bll then grab the total cubes needed variable and drag it onto the graph connect the integer to the object in the equals node then connect the instance to the integer for the cubes collected node in group one next grab the branch node and connect it to the set text node in group number two highlight your nodes and drag them into group number three for group number four hit the space bar and search up game object under game object select set active connect the set active node to the true branch in the branch node then grab the Secret Door variable and drag it onto your graph connect the game object to the instance slot in the set active node highlight your nodes and drag them into group number four and that concludes script number two now that we've completed our scripts counter and cubes let's start working on applying the logic just a side note I made this small secret room as an example but feel free to construct and use any anything else you like cuz remember the main goal of the script is to make a single game object in the world disappear go to CU count canvas logic then go down to udon Behavior drag in the collected Cube logic script into the program source so we have a couple of things to do in our udon Behavior script first under cubes collected we're going to leave that at zero because at the beginning of the game you haven't collected any cubes then under total cubes needed set that to two mainly because we only have two cubes but as you increase the number of cubes in your game you can reflect that change here under collected cubes display it's asking for a text so go to your canvas and grab and drag the collected cubes text into the collected cubes display as for the disappearing game object for me I set up the secret room and wanted the door to disappear so I'm going to drag that into the slot as for you and whatever you constructed you can drag that game object into here now that we've completed the logic for our counter let's start working on applying the logic for the pickup cubes first select pickup Cube number one and then drag and drop the pickup Cube logic script into the program Source under the udon behavior for pickup Cube number one go to the collected Cube logic then grab and drag the cube count canvas logic into the collected Cube logic next under pickup Cube grab and drag pickup Cube number one into the slot then apply the same for pickup Cube number two and that about does it let's see if it works looks pretty good now that we've completed our Cube game let's go over how the script works when you first interact with a cube it triggers an event in a rack node then it goes to a udon Behavior send custom event node after that it plays a game object object set active node which we've instructed to turn off our Cube by setting its value to zero as for the send custom event node this is a pretty special node because it allows us to network between scripts in short I can play two scripts with one event the way this node works is you first give it the identity of the unon behavior you want it to search through then give it the string name of the custom event in that unon behavior that you want it to play once it finds the string name of that custom event it plays the node and we'll go over that detail in script number two so here we are in script number two we've just collected our first Cube and we're receiving the signal from script number one to play the custom event Cube collected so let's go through the steps of how this works first it goes to a set cubes collected node which we're going to use to add a value of one to our Cub's collected variable via an integer addition node raising that variable value from 0 to one in Step number two the UI text updates using a set text node which uses the new value of the cubes collected variable that is converted from an integer to a string and then shown on the UI that you've instructed it to display it on as for step number three all that's happening is an equality check because what we're trying to do is set the value of the bull in the branch node to True using the statement cubes collected equals total cubes needed so far we've only collected one Cube so the integer value of the cubes Collective variable is equivalent to one but the total cubes needed is two so the statement 1al 2 is a false statement and the bull value in the branch node will remain false the branch node has been instructed not to play anything if the statements are false so nothing happens but if we were to collect the second Cube the value of the Cube's collected variable would increase to two then since the total number of Cubes needed is two the statement 2 equal 2 would exist then the value of the bull in the branch node would become true and the true Branch would play leading to step number four as for step number four the signal goes to a game object set active node which we've instructed to turn off our secret door by setting its value to zero and that's pretty much it for all our code congratulations youve made it to the end of the video and you're still awake give yourself a pat on the back though because you've literally just modeled and scripted an entire game which is pretty commendable as for the way you run the game you can increase the amount of cubes in it by duplicating the cubes and then reflecting that value change in both the UI and in the script as for the event that occurs when you're done collecting all the cubes it doesn't just have to be a single door opening in fact it can be multiple things such as fireworks going off and a sound playing honestly the guu the limit with this stuff well uh that about wraps it up thank you so much for your time and I'll see you in the next one
Info
Channel: myneighborswifi
Views: 142
Rating: undefined out of 5
Keywords: Collecting game, vrchat, unity, pick up game
Id: E8ObJbDMisA
Channel Id: undefined
Length: 21min 10sec (1270 seconds)
Published: Thu Nov 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.