Menu Start Game Button

6 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.85
List Price:  €134.19
You save:  €38.34
£79.54
List Price:  £111.35
You save:  £31.81
CA$143.73
List Price:  CA$201.23
You save:  CA$57.50
A$159.93
List Price:  A$223.91
You save:  A$63.97
S$135.54
List Price:  S$189.77
You save:  S$54.22
HK$777.83
List Price:  HK$1,089
You save:  HK$311.16
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,131.88
List Price:  NOK kr1,584.68
You save:  NOK kr452.80
DKK kr715.08
List Price:  DKK kr1,001.15
You save:  DKK kr286.06
NZ$176.75
List Price:  NZ$247.46
You save:  NZ$70.70
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,945.33
List Price:  ৳16,723.94
You save:  ৳4,778.61
₹8,493.77
List Price:  ₹11,891.62
You save:  ₹3,397.85
RM450.75
List Price:  RM631.07
You save:  RM180.32
₦154,938.50
List Price:  ₦216,920.10
You save:  ₦61,981.60
₨27,824.38
List Price:  ₨38,955.25
You save:  ₨11,130.86
฿3,419.79
List Price:  ฿4,787.84
You save:  ฿1,368.05
₺3,519.01
List Price:  ₺4,926.76
You save:  ₺1,407.74
B$608.53
List Price:  B$851.97
You save:  B$243.44
R1,830.80
List Price:  R2,563.19
You save:  R732.39
Лв187.32
List Price:  Лв262.25
You save:  Лв74.93
₩144,627.53
List Price:  ₩202,484.33
You save:  ₩57,856.80
₪365.39
List Price:  ₪511.57
You save:  ₪146.17
₱5,882.91
List Price:  ₱8,236.31
You save:  ₱2,353.40
¥15,643.93
List Price:  ¥21,902.13
You save:  ¥6,258.20
MX$2,007.58
List Price:  MX$2,810.70
You save:  MX$803.11
QR364.41
List Price:  QR510.19
You save:  QR145.78
P1,381.63
List Price:  P1,934.33
You save:  P552.70
KSh12,923.70
List Price:  KSh18,093.70
You save:  KSh5,170
E£5,087.81
List Price:  E£7,123.14
You save:  E£2,035.32
ብር12,764.56
List Price:  ብር17,870.89
You save:  ብር5,106.33
Kz91,790.82
List Price:  Kz128,510.82
You save:  Kz36,720
CLP$98,905.10
List Price:  CLP$138,471.10
You save:  CLP$39,566
CN¥729.56
List Price:  CN¥1,021.42
You save:  CN¥291.85
RD$6,087.13
List Price:  RD$8,522.23
You save:  RD$2,435.09
DA13,485.25
List Price:  DA18,879.89
You save:  DA5,394.64
FJ$231.62
List Price:  FJ$324.28
You save:  FJ$92.66
Q770.23
List Price:  Q1,078.35
You save:  Q308.12
GY$20,913.67
List Price:  GY$29,279.97
You save:  GY$8,366.30
ISK kr13,911.60
List Price:  ISK kr19,476.80
You save:  ISK kr5,565.20
DH1,006.07
List Price:  DH1,408.53
You save:  DH402.46
L1,836.70
List Price:  L2,571.46
You save:  L734.75
ден5,900.06
List Price:  ден8,260.33
You save:  ден2,360.26
MOP$800.26
List Price:  MOP$1,120.39
You save:  MOP$320.13
N$1,840.36
List Price:  N$2,576.58
You save:  N$736.22
C$3,678.42
List Price:  C$5,149.94
You save:  C$1,471.51
रु13,597.49
List Price:  रु19,037.04
You save:  रु5,439.54
S/372.23
List Price:  S/521.13
You save:  S/148.90
K405.36
List Price:  K567.52
You save:  K162.16
SAR375.62
List Price:  SAR525.88
You save:  SAR150.26
ZK2,766.46
List Price:  ZK3,873.15
You save:  ZK1,106.69
L477.10
List Price:  L667.96
You save:  L190.86
Kč2,408.98
List Price:  Kč3,372.68
You save:  Kč963.69
Ft39,689.03
List Price:  Ft55,566.23
You save:  Ft15,877.20
SEK kr1,103.13
List Price:  SEK kr1,544.43
You save:  SEK kr441.30
ARS$102,160.40
List Price:  ARS$143,028.65
You save:  ARS$40,868.24
Bs690.76
List Price:  Bs967.10
You save:  Bs276.33
COP$435,928.80
List Price:  COP$610,317.76
You save:  COP$174,388.96
₡50,434.81
List Price:  ₡70,610.75
You save:  ₡20,175.94
L2,537.51
List Price:  L3,552.62
You save:  L1,015.10
₲779,455.88
List Price:  ₲1,091,269.42
You save:  ₲311,813.53
$U4,474.38
List Price:  $U6,264.31
You save:  $U1,789.93
zł408.66
List Price:  zł572.14
You save:  zł163.48
Already have an account? Log In

Transcript

OK, so to get that game playable again, so that when we press this play button, the game actually starts. Let's go back into our app initialize script. And we need to create a new method. And this will, it's going to be encouraging actually, but this method will Curtin is going to do everything that needs to happen when I gave me to stop, so we don't actually need update so we can get rid of update. And we can run ienumerator. Stop game.

Cool. So this one actually, you see we've got an error already, because our numerators need to return something. And what we can normally do is we could like get it to wait for a few seconds and stuff but we don't want to wait every single time we play the game. We want to only when we press play after we die, we want to maybe wait for a second. When we press play when we first started playing the game. We don't want it to actually like wait for a second we just want to stop playing the game, if that makes sense.

So what we need to do is we need to have a, we can have a local variable. Now we haven't done this yet, inside of this project. So if you're a little bit confused by it, that's fine. I think this is the only instance that will actually use this. But we're going to do is inside of here we can pass some arguments that need to be cold when start game is called. And the argument is we that we're just going to make the variable that we that you're going to need to put in for the argument, we're just going to make it a float.

And we're just going to call this white time. No, semicolon there. And then we can just say, yield, return, not on new. wait for seconds. And normally, we would just put a number in here, but instead of putting a number in, we can just actually put in wait time Which is this float here? Now why is this important?

Why have we done it like this? Well, it means that when we actually call this carotene, we can call it in such a way where we can actually designate how long it needs to wait for whether that's zero seconds, or whether that's one second, or 10 seconds, or whatever. And we'll be using this method for two different purposes for purposes when we end on the game over screen, and we want to start again, or for purposes when we just start the game. So the other things that we want to do inside of start game, change all of these, so we'll copy all these, paste them in there. And we only want the in game UI to be on so the other two will be false obviously, so make these false and make this true. Cool.

We probably want this yield statement underneath all of these instructions here. And then underneath white underneath is yield. We just want to set the players motion back to Whatever it originally was. So we can just grab this copy of this line of code, dump it in here. And we can say rigidbody dot constraints, dot none. So now it's turned off all the constraints.

And the only constraint we do actually want on is the y. So we can go back, dump that in there again, and say, freeze position. Why? Cool. So let's turn them all off, and then turn the why freezing back on. Fantastic.

So you may be thinking, great, we've got this long wall, not really long. But we've got this big method here that kind of explained that it does everything that you know you'd expect it to do. But how do we actually call this method from inside the game when we actually press the play button? So if we press play now, you'll see that nothing happens? Well, we actually need to create a method that the play button can use. So how do we do that?

If we need to create a new method called public, and it's important to say public so we can access it with inside Inspector void play button. Cool. So later on, we'll add some more functional add some if statements inside the play button to do the wait time functionality. But for now all we need to do is write start coding or parentheses start game, which is the name of the couraging. open parentheses again, and now it's asking you can see here it's asking for our wait time. And we're just going to say 0.0 F, which is 0.0 seconds.

And then we're just going to close it off with a semicolon. Awesome. So let's test this out. So if we go over to our game, we can go inside of the in menu UI, we can turn it on just because we're working on it. And we can go to our play button, and you'll see here has a method called on click where we can actually press the Add to list. We can choose the scene manager, drag it into that selection there.

Then we can actually access functions that are on that script. So if we go click on this no functions, we can go down to App initialize, which is one of the scripts that's on the scene manager object. And we can go to play button. So that what that will mean is when we press the when we click this button, whether it's a touchscreen, or we're clicking on it with our mouse, it'll run the play button method on the app initialize script. And when we go over to our app, initialize script and we see Play Button play button, it calls the start game curtain. And the start game co routine, changes our menus waits for however long it needs to wait, which at the moment is note no matter of time, and then puts the rigid body constraints back to in game functionality.

So that should be pretty easy to understand. I hope everyone's following along. But if we press play now and see what happens, we press play. Awesome, so the game starts. And that works great. Let me start that again.

Press play. Once again, I can press play As the game starts playing, and everyone is happy. Awesome. So in the next episode, we'll start dealing with pause menus and things like that and continue on with this menu functionality.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.