Scripts as Behavior Components
- Link: scripts-as-behaviour-components (3:27)
- Notes:
- 0:00 – Scripts should be considered as behavior components in Unity. The first example he gives is changing the color of the cube as you click key buttons. Changing colors could be that of as the behavior of the cube. The script is what is causing it.
- 0:11 – The RigidBody component will automatically give the object mass and gravity unless changed. Meaning when you push play the object will fall down if nothing is below it.
- 0:47 – In the script when you have the gameObject selected, you can put a period(.) then the next layer down until you get to what you are trying to change. For example, gameObject.renderer.material.color – so you can change the color.
- 2:46 – Think of scripts as what turns game objects into characters, vehicles, environment, or scripts that manage the functionality of the game.
Variables and Functions
- Link: variables-and-functions (5:52)
- Notes:
- 0:02 – In this example, – int myInt = 5; – . int is the type, myInt is the name of the variable, and = 5 is the value. In int myInt = 5, int myInt is the declaration, and = 5 is the initialization.
- 0:53 – Start(void Start) is called when the object this script is attached to is called into the game.
- 0:56 – Random, but you can use Debug.log to show information onto the game screen.
Conventions and Syntax
- Link: conventions-and-syntax (4:10)
- Notes:
- 0:12 – A period or dot operator is used to access the thing below it. For example Debug.log, thing of it like, debug is the state, then log is the city. Then after that is the streets or coordinates. Another example is, gameObject.renderer.material.color. First it access the gameObject then selects the renderer then the material within the renderer component and lastly selects the color of the material in the renderer.
- 1:13 – The syntax semicolon is used to terminate a statement.
- 1:48 – Indenting code is not technically necessary but it allows you to read it more easily as it is used to show the functional structure of your code.
- 3:12 – To leave yourself or others a comment you can use // to write a single like comment. Or use /* at the start of a multiple line comment with */ at the end.
C# vs JS syntax
- Link: c-sharp-vs-javascript-syntax (1:54)
- Notes:
- 0:20 – An example of the difference between C# and Javascript, in C# you would write first the type of variable, then you would name it, and lastly give it a purpose or value. In Javascript you would start by using the keyword var for variable, then you would name it, but then using a colon you have the option to declare what time of variable it is, then lastly give it a default value.
- But when creating a function that are actually not that different.
IF Statements
- Link: if-statements (1:27)
- Notes:
- 0:00 – During coding you might need it to make a discussion based on conditions in the game. This is the if-else statement. For example, if the time is before 3pm it will say, “Let’s go on a walk right now.” If the “if” is not reached it will do something “else”. So if it is not before 3pm but past it, it will say, “Let’s not go on a walk right now.”
Loops
- Link: loops (5:33)
- Notes:
- 0:00 – Loops are a way to repeat code over and over, it is sometimes revered to as iterating. And there are four types of loops, the while loop, the do-while loops, the for loop, and the for each loop.
- 0:27 – The while loop starts by putting while then in () we put a conditional, the content of the loop will continue to repeat as long as the conditional continues to evaluate true.
- 1:04 – The do-while loop functions almost identical to the while loop. Except for one difference, the while loops test the condition before running the loop, the do-while loop runs the body then test the condition. Which means the body of a do-while loop is guaranteed to run at least once. To do a do-while loop, you start by putting do followed with open and closed braces, what ever is inside the braces makes up the body of the loop. After the body is the while keyword followed by the conditional, which the loop will only continue if the condition reads true.
- 2:21 – The for loop is also similar to the while loop but uses a different syntax. You start by using the keyword for, then in () there are three specific sections, the first is optional which gives us a place to declare and initialize any variables. This section will run one time at the beginning of the loop. Then the second is the conditional which will be evaluated before the initialization of the loop. The third is another option section which allows us to increment or decrement any variables we want. This section will run everytime the loop activates. Also note that it is semicolons not commas that separate the sections.
- 4:04 – The for each loop is useful for iterating through collections like a raise(rays?). The foreach loop works by running through the ray or collection we want it to loop through. I’m honestly a little confused about this loop, it kind of is a way to display a collection of items.
Classes
- Link: classes (6:00)
- Example scripting and objects
- Notes:
- Classes are basically like a way of organizing functions and variables. Classes are like a way to group things. It doesn’t even talk about the class that much, just random stuff inside of the class that don’t make a difference, but ok.