Main

Part 5 of Module 1: Video 3 Your first Program

In this video, viewers learn about video transcription and code formatting. Specifically, viewers are taught how to write their first line of code and how to use debug statements to view messages in the console tab. Additionally, viewers learn about whitespace – that any additional space added to code doesn't have any effect on the program when compiled. Finally, viewers also learn how to save their code modifications into Visual Studio with the CTRL-S shortcut. Write first line of code Use debug statements to print messages to console Whitespace has no effect when compiled Use CTRL-S to save code modifications

IVGC.course by Dr. Jan Storgards, Course Leader

6 days ago

video free your first program in the last video we created a script and assigned it to a cube if we run our program nothing seems to happen let's stop that that's because we haven't put anything in our script let's do that now by opening up my script by double clicking here's our script loaded into Visual Studio as you can see Unity has already populated it with some lines of code but don't worry about what these mean right now we'll find out about that stuff later first a word about whitespace
wh space is all the gaps in your code made up of spaces tabs and new lines when Unity compiles your code into a program it ignores all white space in between words what this means is you can add as much space to your code as you like and it'll have no effect for example if we do this to our code Unity sees no difference also if we do this Unity still sees it as the same code now that we've modified our text file you'll notice there's a little star on the tab for our script this indicates that th
is file has modifications that are not saved to save it you can go to the file menu and go to the save menu option which has the control s shortcut now the star has gone if we switch back to Unity and press run you'll see that nothing has changed those changes to the Whit space have had no effect let's write our first line of code we need to put our new code in a specific place in our script file for it to work you don't need to understand why for now but we'll be writing our new line within the
curly brackets directly underneath the line with start written on it so what we're going to do is get our program to display some debug text it's very useful to get your program to display debug text as it can help you understand what your program is doing let's start typing in the word Deb bug you'll notice intellisense pops up and it's guessing very well that we won to type in debug if you press return now it fills in the word automatically you'll see a little red squiggly line underneath the
word this is intellisense again telling us that this is incorrect but don't worry it's only incorrect because we haven't finished typing the line next type a full stop you'll notice intellisense has popped up again with a big list of words we'll start typing in the word log just by pressing L intellisense is guessing that we want the word log that's correct so we'll press return next type an open round bracket followed by a speech mark then we'll type in a message I'm going to use hello world o
nce that's done type in another speech mark and then a closing round bracket to finish off this line type in a semicolon that's our line finished let's save our work with control and S when you switch back to Unity after saving an asset externally you'll notice a spinning wheel in the right of unity status bar this shows that Unity is importing your changes let's run our program now you can't immediately see our debug text here debug text is displayed in the console tab if we select the console
tab here there it is there's our hello world text if you don't have the console tab find it under window console that's it for this video in the next video we look at variables and expressions

Comments