Notes:
04: Creating Hello World Application
- - print ("hello world"); prints "hello world" to console
- - every script has to be attached to a game object to run
- - USE THIS INSTEAD OF PRINT COMMAND:
- Debug.Log("hello world");
05: Variables
- are most important in programming
- storing information for health, ammo, money etc.
- the way computers remember data
- "public" variables show up in the inspector, and also can be accessed by other scripts.
06: Writing Expressions with Variables
- use "instantiate" for shooting objects
- variable = variable -1; // equivalent to decrement --
07: Enumerations
- enumerations are lists of things
- "enum" instead of "int", "float", etc
- public enum Weapons {Pistol=0, Rifle=1, ChainGun=2, Plasma=3};
- public Weapons WeaponWeAreCarrying;
- inspector only shows variables, not enumerations
- once "Weapons" is turned into a variable, it shows up as the variable name and appears in the inspector as a LIST.
08: Constants
- consider constants (const) as shortcuts.
- cannot change over time or be manipulated (just like Arduino CONST)
- label constants in UPPER_CASE, to delineate difference between it and variables.
09: Conditional Statements and IF
- for "out of ammo" scenarios
10: For Loop
- weapon modes (shotgun vs handgun)
- for doing similar repetitive tasks
- example:
- for (int = i; i < 3; i++){
- does something
- }
- "i" is very popular to use because it stands for "iterator"
11: While Loop
- can be used to dump all ammo available
- example:
- while(ammo > 0){
- does something
- }
12: Functions Introduction
- void = return data type for things that don't return anything
- encapsulated set of instructions
13: Events Introduction
- Special function that's called automatically by Unity
- example: "Update()" and "LateUpdate()" // called once per frame
- Space.Self = applies transforms relative to local space
14: Function with Arguments and Returns
- Create a weaponFire function instead of calling the code directly.
- EXAMPLE in "PlayerControl" of Project
- Functions can have a string output in it as a return so it can be dumped to Debug.Log();
- Using functions can save an enormous amount of work
15: Classes Introduction
- a class is a way to organize a collective of all sorts of behaviors
- can contain variables, functions, etc.
- Usually, classes are contained in one script each
16: Rotating Objects with the Transform Class
- put instructions under "Update()" because it's redrawn every frame
- allows for illusion of 'continuous motion'
- Check Unity reference manual routinely to see what functions inside classes do
- " Time.deltaTime " is equivalent to "per second"
- tranform.Rotate (0, 90 * Time.deltaTime, 0, Space.Self);
- calls the transform class function "Rotate", and rotates 90 degrees per second.
17: Unity Class Documentation (navigating the site)
- Runtime Classes
- list of all the different classes that gets things done
- clicking on a class will reveal all the functions within the class
- STUDY: Unity Classes Reference
18: Derived Classes Introduction
- not used ALL the time, but can be handy if objects share behavioral functionality.
19: Extending a Class
- useful as a class modifier
- Example: "Enemy" and "SuperEnemy" modifier
- change from:
- public class SuperEnemy : MonoBehaviour {
- change to:
- public class SuperEnemy : Enemy {
- instructions are inherited from "Enemy" class, along with the "SuperEnemy" instructions
- extends functionality
20: MonoBehaviour
- by default, all Unity scripts derive from "MonoBehaviour"
- Javascript automatically derives from MonoBehavior, but C# and Boo you have to explicitly derive from MonoBehaviour
- explore MonoBehaviour
No comments:
Post a Comment