Unity 2D Tutorial How To Create Simple Board Game With Dice Rolling And Turn Based Movement Features

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I will show you how to create simple board game in this game you will be able to roll the die and two characters will perform their movement one by one according to number the Diaries when one of the character reaches the finish line then win sign appears showing which player wins let's create our project from the scratch all I have already are some assets first here I have resources folder created inside this folder I have a subfolder named eyesight's which contains sprites of cube sites since folder chunk 5 font I like board sprite some scripts and 2 sprites of our players so let's get started at the board sprite first reset it scale a NAPA bit position it like that now we need to create board waypoints for our players to work on create new empty game object rename it as work waypoints right-click it and create new empty child rename it as Waypoint now it's very important to reset our parent board waypoints game object so coordinates of it become 0 especially z-coordinate otherwise players will move not in the way we want them to ok let's add color icon to our Waypoint to make it noticeable here it is now we need to duplicate this Waypoint 31 times so we have 32 waypoints by the number of board cells so here we go and selecting them one by one we need to position them around the board first goes to one second goes to third goes to three and so one to the last Waypoint which goes to 32 there we go now we can collapse this board waypoints to clean the hierarchy now let's add our players player 1 and player 2 reset them set all your layer to 5 so they appear above the board scale them down a bit we can leave them at the center because position of them will be controlled by the script here is this script named follow the path in this script we have an array of waypoints we created move speech variable that can be set an inspector Waypoint index that holds number of current Waypoint player occupies and muffle out variable in start method we place the player at the first Waypoint in update method we move the player if movement is loud move method moves player from one Waypoint to another until it reaches the last one at last Waypoint player stops moving drag and drop the script to player one and player two let's set move speed to higher value I will assign waypoints to player a bit later now let's add a die which we will be rolling take one of the die sprite and bring it to our scene set order a layer to five scale it down a bit position it about here now to make die clickable we need to add a box Collider 2d to it there we go to roll the die and get number to move our players will you script name dice here it is first here we have array of die sprites that will be loaded from the resources folder render a reference to change the site's images whose turn variable 1 means its first player turn negative 1 means its second player turn to move quarantine allow it variable will not allow to roll the die until one turn is over in start method we signed sprite renderer component load sprites into a ray from die site subfolder of resources folder and set thy face to show 6 at the beginning onmousedown method is invoked if we left click over the die collider is needed for that so if game is not over game control script will be examined in the moment and Carlton is loud then roll the dice Colton is started in this karate with his loud co-routine invocation first then we go through the loop 20 times in which number from 0 to 5 is being randomly selected and image of dice changing each iteration is post by 0.05 seconds when loop is over we pass random value from 0 to 5 - game control script which controls player movements we have to increase it by 1 because everything in computer wall starts from 0 then if it's player 1 turn to move then move player method phone game control script is involved with parameter equals to 1 past if it's player to turn to move then move player method is involved with parameter equals to true past after that turn is switched by multiplying it by negative 1 so one becomes negative 1 and negative 1 becomes positive 1 and Quarantine is allow it again drag and drop the script to dice game object and let's rename it as dice actually now we need a game object to control players movement create new empty one to rename it as game control reset it this game object will use game control script here it is first we have a reference to some UI text game objects which we didn't create yet first one is who wins text which is named here is who wins text shadow by mistake I wanted to create a shadow for this sign but changed my mind and forgot to renamed this variable but it's ok this will not affect the functionality of our script I'm sorry anyway so next text game objects up layer one move text and player to move text that indicate whose turn to move at the moment then we have references to players game object the eye sight stone which holds number of current move points and here a player 1 and player 2 start waypoints variables that help us to determine where each players move starts and here is blue in game over variable if it's true then game is over in start method would perform all of the assignments find UI elements and players game objects to control those this allow each player to move toward win sign off turn player one move text on so which players one turn to move and turn player to move text off the main part of magic happens in a bed method but first let's take a look at move player script which is invoked from die script when dice is thrown this method takes one parameter which is int number if it's 1 then player 1 is allowed to move if it's 2 then player 2 is allowed to move update method so if player is moving player 1 in this case and which is worth Waypoint with index that equals to player starts Waypoint plus number of throwing move points then player stops at this Waypoint whose turn text is enabled to next player and this current Waypoint that player occupies at the moment becomes starting Waypoint for the next turn same for player 2 then if player 1 reaches the last work Waypoint then who wins sign appears showing that player 1 wins game over is set to true so game is over same code for player 2 accept the fact that I forgot to put two lines of code that disabled player move text into block of code for player 1 you can do it by yourself drag and drop this trip to game control game object now let's create UI elements create new canvas and set it scale mode to scale with screen size right click on canvas and create new UI image it will be player 1 icon duplicate it this will be player 2 icon select first one drag and drop player one sprite into source image slot select second one drag and drop player 2 sprite into source image slot as well and for player 1 icon at the top right corner and curve icon to head bottom right corner double-click to focus on icon scale it down a bit position it like so same for second icon then right-click on canvas and create new UI text it will be player 1 move next letter casing is important make a mistake in just one letter and script will never find this game object and you will get an error type your move into text field change font family by dragging and dropping from two like in two modified text options as you wish double-click to focus on this text position it under the player 1 icon duplicated rename it is player to move text position it above the player 2 icon ok right-click on canvas and create new UI text it's going to be who ensign anchor it at the center text will be modified by the script but let's just type in player X wins to hold the place change font family modify phone size set alignment set overflow options to overflow so text will not disappear if it goes out of the boundaries of the container change color last thing I forgot is to assign board waypoints to players select player 1 lakh inspector window so it shows player 1 options select all of the waypoints and drag and drop them into Waypoint slot or follow the paths replete edge to player 1 do the same for player 2 we are done now we can hit play and see how it works its player 1 turn at the beginning roll the die by left click rolling stops player moves by the number Diaries now which turn of player 2 roll the die directs 6 player 2 makes 6 steps and so on make your bets the game continues until one of the player reaches the last Waypoint so now you know how to create simple board game hope you like this tutorial thank you for watching see you next time you
Info
Channel: Alexander Zotov
Views: 117,845
Rating: undefined out of 5
Keywords: alexander zotov, unity tutorial, unity, game development, unity game, make unity game, unity 2d, Unity Tutorial How To Create Simple 2D Board Game With Dice Rolling And Turn Based Movement Features, unity board game, unity board game tutorial, unity board, unity 2d board game, unity simple board game, how to make board game unity, unity board game movement, unity board game dice move, unity board game example, how to make board game in unity, board game, unity 2d tutorial
Id: W8ielU8iURI
Channel Id: undefined
Length: 10min 36sec (636 seconds)
Published: Tue Jun 05 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.