1
00:00:00,000 --> 00:00:00,000
Hello there.

2
00:00:00,000 --> 00:00:05,000
So in this video, we actually going to make the menu work and we're going to begin by creating C-sharp

3
00:00:05,000 --> 00:00:06,000
script.

4
00:00:07,000 --> 00:00:12,000
I'm going to call it UI mane and let's take canvas and drag it over here.

5
00:00:13,000 --> 00:00:14,000
All right.

6
00:00:14,000 --> 00:00:16,000
Now, let's take a look at this.

7
00:00:16,000 --> 00:00:20,000
This is the parent that contains menu items as it's children.

8
00:00:20,000 --> 00:00:21,000
Right?

9
00:00:21,000 --> 00:00:23,000
So this is the child of the canvas.

10
00:00:23,000 --> 00:00:24,000
This is the child of the canvas.

11
00:00:24,000 --> 00:00:26,000
And this is the child of the canvas.

12
00:00:26,000 --> 00:00:29,000
And from the parent script, we can control those objects.

13
00:00:29,000 --> 00:00:31,000
Let's go inside.

14
00:00:32,000 --> 00:00:33,000
I'm going to close all but this.

15
00:00:35,000 --> 00:00:39,000
Let's delete update for now and delete this green line and don't like it.

16
00:00:39,000 --> 00:00:46,000
And in the start we're going to make for a loop that's going to act as long as this canvas has some

17
00:00:46,000 --> 00:00:47,000
children in it.

18
00:00:47,000 --> 00:00:48,000
So let's do.

19
00:00:54,000 --> 00:00:56,000
Transform dot child count.

20
00:00:56,000 --> 00:00:57,000
Right.

21
00:00:57,000 --> 00:01:03,000
And inside, just for example, let's try to switch off all of the children.

22
00:01:03,000 --> 00:01:06,000
Let's do this transform, get child with an eye.

23
00:01:06,000 --> 00:01:09,000
So it's going to cycle from zero to the last one.

24
00:01:09,000 --> 00:01:14,000
And do game object set active, false.

25
00:01:14,000 --> 00:01:16,000
Let's see what it gives us.

26
00:01:16,000 --> 00:01:18,000
Let's go back to Unity.

27
00:01:18,000 --> 00:01:23,000
Let's switch on these and then press the play button.

28
00:01:26,000 --> 00:01:31,000
Look, all of them were switched off because we cycled through them with the help of for loop, and

29
00:01:31,000 --> 00:01:33,000
then we switched off one by one.

30
00:01:33,000 --> 00:01:37,000
What if after this one we choose to switch on the one we like?

31
00:01:37,000 --> 00:01:43,000
For example, let's do this serialized field private game object.

32
00:01:44,000 --> 00:01:46,000
Let's say, settings.

33
00:01:47,000 --> 00:01:47,000
All right.

34
00:01:48,000 --> 00:01:52,000
And then in here, after for loop, we're going to say settings.

35
00:01:53,000 --> 00:01:54,000
Not set active.

36
00:01:54,000 --> 00:01:55,000
True.

37
00:01:55,000 --> 00:01:57,000
Let's go and try that.

38
00:01:58,000 --> 00:01:58,000
In the unit.

39
00:01:58,000 --> 00:02:02,000
He lets select canvas and drag settings to the settings field.

40
00:02:02,000 --> 00:02:04,000
Now let's go and try this.

41
00:02:04,000 --> 00:02:05,000
Let's hit play.

42
00:02:09,000 --> 00:02:13,000
And you can see everything was switched off and settings were switched on.

43
00:02:13,000 --> 00:02:17,000
And basically, this is the entire code we're going to use to switch between menus.

44
00:02:17,000 --> 00:02:19,000
Let's go and modify it by just a bit.

45
00:02:19,000 --> 00:02:25,000
Let's select all of these code in the start press alt, enter and choose extract method.

46
00:02:26,000 --> 00:02:31,000
I'm going to name it as switch menu two.

47
00:02:31,000 --> 00:02:32,000
We can delete it from the start.

48
00:02:32,000 --> 00:02:34,000
We don't need it for now.

49
00:02:34,000 --> 00:02:41,000
And here instead of private, I want to make it public and in the parentheses I want to pass a game

50
00:02:41,000 --> 00:02:41,000
object.

51
00:02:41,000 --> 00:02:45,000
So let's do this game object UI menu.

52
00:02:45,000 --> 00:02:52,000
The UI menu we want to switch on and instead of settings here we're going to do UI menu set active.

53
00:02:52,000 --> 00:02:53,000
True.

54
00:02:53,000 --> 00:02:55,000
We can delete the serialized field.

55
00:02:55,000 --> 00:02:56,000
We don't need it now.

56
00:03:00,000 --> 00:03:04,000
And now let's go to the unit and see how we can use this function.

57
00:03:05,000 --> 00:03:08,000
I'm going to switch off all of the elements in.

58
00:03:09,000 --> 00:03:10,000
Except the main menu.

59
00:03:10,000 --> 00:03:18,000
I need main menu, and then I want to go inside the main menu, find my shop button, and it has a component

60
00:03:18,000 --> 00:03:18,000
button.

61
00:03:18,000 --> 00:03:19,000
You might see it before.

62
00:03:19,000 --> 00:03:22,000
You might know how to use it, or you might just seen it in the previous video.

63
00:03:22,000 --> 00:03:24,000
Me putting it on the game object.

64
00:03:25,000 --> 00:03:29,000
What we need to do here and this shop button is already a working button.

65
00:03:29,000 --> 00:03:33,000
It's clickable and you can add a function on click to this button.

66
00:03:34,000 --> 00:03:35,000
Let's try and do this.

67
00:03:35,000 --> 00:03:37,000
Let's go here and click plus.

68
00:03:37,000 --> 00:03:44,000
Then we can drag an object here and then choose a function from that object.

69
00:03:44,000 --> 00:03:49,000
We have a UI main component on it, and then we're going to go and find switch menu to function.

70
00:03:50,000 --> 00:03:53,000
Now, as a parameter to pass, we need to give it a game object.

71
00:03:53,000 --> 00:03:58,000
And because this is a show button, we can give it a shop UI game object.

72
00:03:58,000 --> 00:03:58,000
Now let's go.

73
00:03:58,000 --> 00:03:59,000
Not too far.

74
00:03:59,000 --> 00:04:01,000
Find the shop UI.

75
00:04:01,000 --> 00:04:04,000
Open it and find clothes button.

76
00:04:04,000 --> 00:04:10,000
And here we can hit plus drag the canvas and then find the UI switch menu to.

77
00:04:11,000 --> 00:04:13,000
And we're going to choose Main Menu.

78
00:04:13,000 --> 00:04:16,000
Now let's go to play mode and see what it gives us.

79
00:04:18,000 --> 00:04:23,000
I can go to shop and I can press close button and go back to Main menu.

80
00:04:24,000 --> 00:04:25,000
Pretty cool, right?

81
00:04:25,000 --> 00:04:26,000
Pretty simple.

82
00:04:26,000 --> 00:04:28,000
Now, let's do this for other stuff.

83
00:04:28,000 --> 00:04:32,000
Let's find settings button plus canvas.

84
00:04:33,000 --> 00:04:37,000
Switch to find settings UI we prepared.

85
00:04:37,000 --> 00:04:38,000
Where is it?

86
00:04:38,000 --> 00:04:39,000
Here.

87
00:04:40,000 --> 00:04:41,000
I'm going to draw the main menu on the top.

88
00:04:41,000 --> 00:04:42,000
That's what I want.

89
00:04:45,000 --> 00:04:46,000
What else we have here.

90
00:04:46,000 --> 00:04:49,000
We have mute button, but we're going to take care of that later.

91
00:04:49,000 --> 00:04:52,000
When we say turn up the volume and sounds and so on.

92
00:04:53,000 --> 00:04:55,000
So let's just close this for now.

93
00:04:55,000 --> 00:04:57,000
Top to start, we also going to set up in next video.

94
00:04:58,000 --> 00:05:02,000
Let's go to settings find close button, set it up with a canvas.

95
00:05:04,000 --> 00:05:07,000
UI switch tool and we're going to switch to Main menu.

96
00:05:08,000 --> 00:05:11,000
We're not going to do the same for Main menu in the past UI.

97
00:05:11,000 --> 00:05:14,000
It's going to have a bit different functionality.

98
00:05:14,000 --> 00:05:14,000
All right.

99
00:05:14,000 --> 00:05:15,000
So let's leave it for now.

100
00:05:15,000 --> 00:05:18,000
And in the shop we took care of close button.

101
00:05:18,000 --> 00:05:19,000
So basically this is done for now.

102
00:05:20,000 --> 00:05:23,000
Let's go and overview the code just to avoid any confusion.

103
00:05:24,000 --> 00:05:32,000
So we added a button and this button has on click event and on click we added a function from canvas

104
00:05:32,000 --> 00:05:38,000
that is named a switch menu tool, which is exactly this function over here.

105
00:05:39,000 --> 00:05:42,000
Then this function requires a game object inside it.

106
00:05:42,000 --> 00:05:47,000
And we passing a game object by dragging this object to this field over here.

107
00:05:49,000 --> 00:05:57,000
So then when this function called, we have a for loop that cycles through all of the children under

108
00:05:57,000 --> 00:05:59,000
the canvas and switches them off.

109
00:06:02,000 --> 00:06:04,000
And after that it takes the game object we chose.

110
00:06:04,000 --> 00:06:07,000
We passed inside and sets it to active.

111
00:06:07,000 --> 00:06:10,000
And by that we switch in between menus.

112
00:06:10,000 --> 00:06:11,000
Very cool, right?

113
00:06:12,000 --> 00:06:13,000
Yeah, I hope so.

114
00:06:13,000 --> 00:06:14,000
Okay, let's go to the next video.

