02 Language Notes
Logical Operators
&& = both true
|| = either true
! = false to be true
== = true
Types of Data
String = text (ex. Console.WriteLine("Hello World");)
Int = Whole number (ex. Int area = 120;)
double = decimal number (ex. double weight = 1.54;)
Float = less accurate decimal (postfix f)
Decimal = more accurate decimal (postfix m)
Bool = true or false
var = any data type can be used
String Info
" = for having Quotation marks in strings
Data in strings(string interpolation) = use $ before the quotation and then {} around the variable
\t = adds a tab
\n = creates a new line
Methods
blocks of code defined within a class that controls game behavior, logic, and interactions.
Start() = Called once before the first frame update
Update() = is called once per frame and is primarily used for handling input, game logic, and non-physics movement.
LateUpdate() = executes once per frame immediately after all Update functions have finished, ensuring it captures the final positions of objects (smooth camera following)
FixedUpdate() = runs at a fixed time interval independent of frame rate, making it the dedicated place for all physics calculations (rigid bodies)
void = the method doesn't return a value
public = shows the class in the inspector allowing for other game objects to be utilized in the code. Also lets you change variables within the inspector.
. = directs into a method (think of it like a directory, you put a dot after a method to use the commands attached to that method.)
transform = grabs the transform component of the object
transform.Translate/Rotate = Used to move the position/rotation of said object by however many units.
Vector3 = x y z
Vector2 = x y
new = keyword to create something
Instantiate = Creates an object ex. Instantiate(object, position, rotation, parent)
GameObject[] = Creates an array to allow for randomness
Random.Range(From, to) = Chooses a number from the chosen length (must go one higher than the number you want for the length).
.triggered = triggers in an if statement if button is pressed.
InvokeRepeating("MethodName", Delay, Interval) = Does a method repeatedly.
Invoke("MethodName", Delay) = Does a method once
AddForce(Vector3 * number, ForceMode) = Adds force to the rigidbody
ForceMode.Impulse = Instant force application
ForceMode.Force = Applies force over time
GetComponent<> = Gathers info on an component
GameObject.Find("string") = Find a game object in a scene and get a component from it.
ReadValue<> = gets a value of a variable
If & Switch Statements
Switch
int choice = 2;
switch(choice);
{
// "1" is the thing that has to be true for this case to run (can be any form of data)
case 1:
Console.Write("example1");
// "break" stops the code so it doesn't run the rest.
break;
case 2:
Console.Write("ex. 2");
break;
// default = else(no match)
default:
Console.Write("no match");
break;
}
If
int x = -10
if(x<0)
{
Console.WriteLine("less than 0");
}
else
{
Console.WriteLine("greater than zero");
}
Loops
for
/* initializer creates a variable, condition is what is needed to stop the loop
and the iterator is what runs every time the loop runs */
for (initializer; condition; iterator)
{
// code block
}