Create Hidden Objects Game in 1 Hour | Unity 2D Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello boys and welcome back hope you all are doing great so in this video we are going to see how we can create a simple hidden object game so as you can see here I have this simple scene here I have this timer which is going down and I have these images they are showing which I need to find so if I click on this seahorse I get one of the hidden object now I need to find all of them [Music] once I have detected all of them you can see our game is completed and we can move on to next and very low to the level and once the timer is over and let's say if we did all all of the hidden object within the time then we have a game over so this is what we are going to create in today's video so without any further delay let's case [Music] as you can see you guys I have opened a startup project so if you want to download the startup project the link will be in the description you can just download it so here I have already created a canvas it is canvas you can see I have this timer where we will be showing our time then we have this hidden object info folder so this holder will be holding the icons of a hidden object which we need to find then we have this Help button where I am clicking on it we will be like highlighting the one of the hidden object then we have this game complete panel and the next button so this is what I have already created and we have some art assets here which we are going to use and a prefab of a hidden object icon so if I go and do that you can see here I have image and text so to show the image and the name of the object so now the first thing we need to do is we will create our in pearl object holder so click on this create and create a empty game object resell its position rotation and let's call the object holder so the first thing we'll do is we are going to populate our option what we have to do is just drag our object art asset and place it here and we will be arranging them with different scale and rotation so we can just change its header value and then we can scale it lets it down like this and we have to do it for like all of them [Music] [Music] [Music] okay so after we have populated all our objects we need to add a Collider to them just select all of them go to add component and here we are going to add a circle 2d Collider you can add any color of your choice but I am here adding circle Collider so as you can see here right now all of them are having the colliders okay now let's create a script showing scripts folder right click and create a new C shaft script and let's call it level manager let's open it now we'll make our level manager and instance so for that will create a static variable called public static label manager gangsters and in away we are going to assign the instance of void awake is equal to if our instance is equal to null then instance is equal to this and if our instance is not equal to love then be placed fry this game object okay we make it an instance so that it becomes easy for us to exist this script from another other scripts let's remove this so we need a list to store all our object for that we will create a new class of public law and we'll call this theta object theta and in this villain object data we will be having a public string name then public game object object or we'll call this return object and we will also have a public moon make header by default it will be false okay and let's make it system dot serializable so that we can edit it from inspector so here we'll be creating our private list of our hidden object and we'll call this item object list but this list will hold all the hidden object which are available in the scene and we'll make it a civilized field so that we can edit it from inspector let's create a new game object reset it and it's called is level manager and it will track the level manager on it seconds here we have this list and we have this our hidden object so what we will do is we just lock the level managers so can do it we can edit it as you can see we have 14 objects so we'll create our 14 elements here let's track one by one we'll call this card [Music] after populating the list will now select the object from the list randomly which will be hidden will create a new list private return list and we'll call this active return object list so this list will hold the hidden objects which we need to find we will create a new method olive oil assign return objects so we'll first loop through all the hidden objects calm and we are going to disable their Politis so it an object list I don't get an object component provided to de Raadt n equal to false now the reason we are setting all of them forward sin because reborn only active hidden objects Collider to be active for that we can detect them when we tap on them so once we have disabled all of their colliders now we want to randomly select some of the hidden objects which will be activated objects and we will activate their Collider for that will create a in k equal to zero this is a local variable just to keep the count and we will have a while loop while K is less than 5 so right now I want PI activity objects for each game so here I am setting it to fine if you want more than 5 or less than 5 you can change the value or what we can do is we can just create a private int max back to return objects count I will set this to fire and we will make it a serialized field so again we can edit it from inspector we can just copy and paste it here okay so what we are checking here is while our K is less than max activity an object count we need to keep getting the hidden object randomly from this list what we will do is we will create a int random Val is equal to random dog range our range will be from zero to our hidden object list dot-com okay now once we are and Umrah selected any integer between this range we will check if our hit an object list our random value dot make it up so if this is false then only we are going to select the hidden object at this index or first we will make this proof equal to true then we will activate its collider so just copy and paste it and instead of I will call random value and we are going to add this hidden object to our this activity object Lee so at total of the list not I just call being a stir this year and one more thing we need to do is once we decide to make it an activity object we need to rename it so what we do is we just call this hidden object list and we are going to access the hidden of the game object dot name and it will be equal to okay now now the reason we are changing the name of our object which will be equal to the index so it will be go from zero to this poor zero one two three four like that is just to make sure when we detect any game object we can also track the same icon for that object in our he 1 so we are doing going to do that in our next thing so first let's do this so once we have selected all our hidden object let's call this in our star so void start assign her the whole thing and before we can assign this with it to set our act to the object is equal to new okay and to do is we'll clear it so in case we have any information okay one more thing our remaining so after we have selected at the hidden object we also need to increase our K so k plus plus and one more thing instead of setting these to false we need to on a wonderful add also will make it too but I select this object holder as you can see her let's go to wireframe mode so only the activation objects are having the colliders and colliders of all the other object is disabled so this is what we need to do now we also need to detect the object before that we'll go to our update letter so up and here we are going to check so if input dot gate mouse button down zero so if player taps on the screen then we need to check where we have tapped so for that we need a recast first we will create a vector3 course which will be equal to camera wrote main door trail to world point and it will go everything toward mouse position we need to check where we have tapped so we are getting the mouse position and converting into a boiling point then we create a recast it truly will polish it which will be equal to physics 2d thought because our origin will be the position and our direction will be vectors we rod 0 as it is to Lee we do not have any direction and then we will check if it is not equal to null and fill dot Collider is not equal to if both of them are not plunge then we're just going to let set debug or deeper or object name we'll just call it put on collider toward the object so just for testing purpose let's comment this code where we are changing the hidden object name so just so that we can see the name when we tap on it let's click on this player and you can see our object we have flipped this player so 0 let us click on this 0 this 0 as you can see guys we are getting the name of our objects which we are tapping let's go back and let's undo this okay so what we can do here is once we have detected at the object we can just be activated so what we will do is hit Collider game object on the duct to 200 K and we will also remove it from our act to get an object list so we'll create a for loop and it will be this activity object and I will be drowned so here we'll check if our active object list i dot hidden object dot name is equal to our it dot collider tour game object dot name this name is same so we will just remove the object from that index or active out at least rod remove at I and we also need to break so we break from this book let's also keep a track of how many hidden object we have found we will create a private and total freedom objects boom I had to start it will be zero and we will just copy this and place it here so when we are assigning the hidden object we are going to set it to zero we are going to increase it by one so he totally object form plus first and we'll just type so if our tutorial on object fog is greater than or equal to one Max is activity' not the count today you will just debug that we have computed at day one level okay let's go back and let's try so let's click on play and if we go into the debug mode you can see here we have this activity on object list one is lemon and then we have this card and we have this moves Angira and then crate okay so once we have found all of the activity an object our level is completed now most of our mechanism is complete now let's try to add on UI controller in script tightly and create a new C sharp script and Polly why manager so double click on it we will also make it instance public static to our manager instance it will boot over level manager let's copy this and paste it here to the same hole no change so we'll create our private game object and call this game panel so once our game is complete we'll activate this game panel and we'll make it a civilized way so that we can edit it for inspector then we also need a prefab so private game object return object icon prefab and we will also make it a civilized field and we also need one more thing hidden this one here an object icon holder so if we go back to our editor let's create a new game object reset it and call this d-y manager and let's dragged our script oil so here our hidden object icon folder so what is it it is this you can see here this police dy element is our holder so this will hold all the hidden object I passed now you can see here I have this antenna hold up on this container hold up I have this global direct component as well as mass component and inside that we have this hidden optic info folder and this info folder has a horizontal layout group on it we're spacing is 25 and you can see this all of these are I'll take only this monistic and in this content holder and I was thrown red component our content field is filled by this hidden object in folder and we are going to scroll only in horizontal direction so only horizontal istic now in our UI manager just drag this hidden object info folder to here now we need an icon prefab so in prefab folder we have this prefab let's drag it here and for game path just drive it now let's go to prefab so open it our hidden object icon is nothing but for UI object in which it has a child of image and text so this is what we have word now when we click on play we select our hidden object from them and then we also need to create icons of that respect to hidden object here so for that we will create a new method we will call this public wired populate done object and [Music] object data with all these active data object list so we'll create a for loop I took it out that leaves dot count and we need to instantiate the prefab or we'll create a game of the icon which will be equal to instantiate a word get an object I call prefab and its parent will be our hidden object holder doll transform will rename it so icon dot name is equal to I told an object list I drawed hidden-object dot name will set the image so image for that we need to call using unity engine dot why image tiled image is equal to we are going to get the image so I PI dot transform dot get child zero nor gate component image and same thing for our text so text child text equal to get child one and this will be a text okay so as you can see you here I am setting that gate child and index 0 and get child at index one not the reason I am doing phase is because if you go to our prefab you can see here the object icon which has the image component he's at the index zero and a tech object text which has the text component he is at index 1 so that's why I am get setting this child z11 so once we get respect to child now we are going to set them so child image dot price is equal to we'll get to it an object dot red component sprite renderer dot sprite and child text dot text is equal to AK children object list I dot name now as you can see here I am setting our image equal to the sprite of our hidden object so if we go back and select any an object it's a card you can see here it has a sprite renderer component on it and in that we have this pride here so we are just setting despite to here now once we have done this let's call this method in our level manager so once we have selected all our hidden object we will know populate our UI manager so UI manager or instance talk of blade over hit an object icon we have this active object list let's go and try to play before that let's select our you are manager alert CEO let's click on play as you can see here lies we are showing the activated object here let's click on rabbit okay let's click on flare and Lesley power moves from each one it is not there so we have code as well as card so let's click on trying to keep on partner and you can see here it is not capable so we are correctly showing our object belong we also need to let's deactivate this icons once the corresponding or respect to object is deactivated so for that what we will do is we will keep the track of all our icon so here we will create a private list of game object and we will call this data object icon list and we will just activate this list is equal to new list so when we are populating we are just going to clear this first okay and here once we have set all the icon thing we are going to add it to add so now when we click on the activity object we deactivated object now we also need to deactivate the icon for that we need to create a method so here will create a public oil and call this check selected data object and in this we are going to pass our spring and the spring will be object name we'll look through all our this hidden object icon list so we'll create a for loop will call this count I will check if our none of that icon list I thought name is equal to one object name so if it is true then we will just be activated objects older object icon list I not said acting to pause and then Gavin go break from the loop we need to call this matter so in our level manager when we click on this whenever we tapped on our game object we need to call this matter so here we'll call our UI manager instance dot check selected it an object and we'll just send it to name so you click left click on this player I can see both of them for deactivator moves and different giraffe and we have this level carpet oh ok so in in UI manager we have this game pal and we need to activate it once our level is complete so we'll create a Gator for so public game object game panel and return our came back in level manager once our level is complete we'll call this one manager tour instance dot came panel door said active to please click on play papa once all of they misled identified we show this game complete panicked okay now we also need to show the timer will create evil eyes feel private text text and for this time motives also we are going to create a little opening Thanks by text you and in our level manager we are going to set it so here we'll create a new little ice field a private float I'm limit and here we will create a flow time so this time Luud will be the maximum time we are going to do for each gameplay and current time we are going to use to track the escape time time time limit and our manager rod instance tour timer text dot text is equal to our time I update we are going to change over time so notice if our current time minus equals time at all Delta time and we are going to check if our current time is less than equal to zero then you stop they will complete debug that naman lost we will activate our panel and we also need to set our timer so we will create time and for time span we need to use using system we are going to get this so for random.range we are going to use unity until dot random dot range and not system and for time span dying is equal to I and rod from seconds that is our current time so we are going to convert our this flowed into this time span and here in our UI manager rod instance torn timer text dot text will be equal to 4 times dot through string we need to format our string in our minutes and seconds okay let's go back and rest right Yui manager or we have this timer text so let's assign our timer text to it and in level manager our time limit is zero so let's set it to be two and a half seconds over two point five into sixteen it's two and half minutes so it ends here let's let's say this to be about 30 seconds or maybe 10 seconds just to take whether our game mode is working or not [Music] seconds here our came over a spot now this thing is called every frame so for that what we'll do is we'll create a public in a game status so this will keep track of game status or whether it is playing or whether it is next so we'll just keep track of it will create our private game status game status which will be equal to game status toward next by default and in update we are going to check if our against it as equal to games let us start playing so if it is playing only ten we can tap as well as update our current time and once we have done assigning our activity an object we are going to set our game status is equal to gangsta to start playing and here once our level is completed we will just call our game status is equal to game second start next so one it once it is completed we are going to change our game status and also we are going to change when we lose our working we also need to have a hint let's say players get stuck in between so we just need to show him some hint so we have decent button here we'll create a method probably called in de prata and in this end button we're going to call our level manager method so in level manager we're going to create a public by numerator and method and in this method what we do we will randomly select any activity object Oh [Music] a random fan equal to unity engine random dog range our range will be from zero to activation of decreased rod pound and we'll save this scale first for vector three for each null scale is equal to a2 this fandom value to an object or top font or robot scale now we are going to increase the scale so whatever the scale is last equals or we'll just create [Music] equals our original scale into 0.25 then we will wait for few seconds so he'll return you wait for second so let's say you two point two five seconds and then again we are going to set it open scale to its original scale just call for UI manager I will create a dart 14 our label manager toward Eastern stored in method and you also need a method for our next button so public boiled next button when we click on Next button viewing it to the reload our level sold for all using unity engendered scene management and seeing manager dot load theme team manager dot your active scene about building decks ok let's go back to object here in our button component just click on this add add your you a manager and just select the Run button method and in game component game complete panda in next button to the same and select the method next button ok so let's click on play and try okay let's increase overtime were twins for ten seconds let's say 60 60 seconds let's try our hand button so if I keep on hitting butter we're gonna see one of them just pop up there is one issue I don't know why one thing nice so we are multiplying our original scale with 0.25 so 0.25 will make it 1.25 so if we try again you can see it is poking up yep now over here a hint but as well as our next button is working so what we can do next is let's create a new C sharp script and we'll call this hidden object holder and it's double click on it open it and what this script will do is it will let us copy this so in our level manager we have a list or hidden object Italia so let's copy that and let's paste it here and let's create a cater for this copy-pasted instead of private it will be public to reset that h to capital will create a gator we will return our object is talking so let's go back here is object holder it's called is data object folder and let's track the script on it and now we have this list here so what we have to do is this list right now is on level manager and we don't want we want to use this list in this area objects so let's create a list [Music] okay so once the list is up later now we need to remove this so in level manager instead of directly accessing the list what we'll do is we'll create a return object holder game object I will call this the object holder and we'll get some errors or as you can see here we are now dating this error because this list does not exist or what we can do is just on our return of the holder dot and in store this will for this header okay this should be public this will give it an object list there's copies and let's replace our hidden object list by that okay so let's go back and it's tryna okay we are getting some issue here there before got to save this thing restaurant okay so now this here we have this field where we can add our he turn of the corner so just try over here on of the holder there and let's keep on playing and it still works the same now the reason we did this is because let's say we want different types of real objects so I can just right click duplicate this the activities so in this car instead of cordless add banana then it's probably said cow let's add lime we also need to make changes here so it so-called line in sub-zero fridges yeah let it be Apple okay so if I go to a lil manager and he stroked this one I drag it this one and let's keep on play and you can see yeah let's try a name you can see we are showing the Apple then PR so in this way we can have different types of label so now what we will do is let's try to create a prefab of this so we'll create a new folder in our prefabs for apologizing level let's call this an object folder 1 as delayed is and this will be her optic holder to still it is okay so now we have related them and we need to instantiate them so in our level manager will create a object folder for - intro let's call these prefab that's copies we are getting the IRA's just we need it so here our object will die which is hidden of the polar is equal to instantiate and we are going to instantiate our head up up take hold of prefab about transform would you wait to 3.01 our rotation will be quaternion dot identity okay just click on play I can see here we are pawning this year of the polder and we are creating I can just replace it with one of the older to me and then it will spawn the second one so he will see you guys just by replacing this return of the holder prefab we can define which level we want so you can have multiple levels of this with different objects and we can just activate whichever lemon balm so this is for this view our tutorial guys the entire project is on github so you can just go to get up and get the entire project from it so I hope you have learned something new and enjoyed this video so thank you guys for watching and I will see you in the next video [Music] you
Info
Channel: MadFireOn
Views: 16,228
Rating: undefined out of 5
Keywords: unity tutorial for beginners, unity tutorial for beginners 2d, hidden objects game, create android game, create android game in unity, learn unity programming, learn unity engine, unity for gamedev, unity for game developers, how to become game developer, game developer tutorial, create video game in unity, create game for iphone, hidden objects game in unity, unity tutorial for beginners 2020
Id: ik9xKSNb9wU
Channel Id: undefined
Length: 47min 52sec (2872 seconds)
Published: Tue Apr 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.