What is scripting in Unity? Flashcards

1
Q

Variables :

A

Variables hold values and references to objects (you can see objects as “bigger”
variables). They’re like a box that holds something for us to use. Variables start
with a lowercase letter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Functions :

A

Functions are collections of code that compare and manipulate these variables.
Functions start with an uppercase letter. We organise code in functions so that
they can be easily reused multiple times in different parts of the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Classes :

A

Classes are a way to structure code to wrap collections of variables and
functions together to create a template that defines the properties of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Variables (between the lines)

A

Private variables allow your code
to be cleaner, since you know that the value of those variables can be changed only inside that
class. This makes debugging and maintaining the code easier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Variables (between the lines)

A

f you want objects to communicate between themselves you need some variables (or
functions) to be public.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

There are a number of
functions that run
automatically inside Unity :

A

Awake - is called only once when the GameObject with that component is instantiated. If a GameObject is inactive, then it
will not be called until it is made active. However, Awake is called even if the GameObject is active but the component is
not enabled (with the little checkbox next to its name). You can use Awake to initialize all the variables that you need to
assign a value to.
——————————————
Start - like Awake, Start will be called if a GameObject is active, but only if the component is enabled. For more
information on the differences with Awake, see this video.
——————————————-
Update is called once per frame. This is where you put code to define the logic that runs continuously, like animations,
AI, and other parts of the game that have to be constantly updated.
——————————————-
FixedUpdate - is when you want to do physics work.
——————————————–
LateUpdate - is a function that’s similar to Update, but LateUpdate is called at the end of the frame. Unity will look at all of the
game objects, find all of the Updates, and call the LateUpdates. This is good for things like the camera. Let’s say you want to
move a character in your game. And then he’s bumped into by another character and ends up in a different position. If we
move the camera at the same time as the character, there would be a jiggle, and the camera wouldn’t be where it needs to be.
So, basically, it’s a second loop that comes in very handy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Writing functions (between the lines)

A

When writing a function, remember that functions start
with the returned type of the function at the beginning,
followed by the name of the function, and then the
parameters in the parentheses (if any). Function names
start with a capital letter and the body of the function
goes between the curly brackets. Here’s an example on
how to write a function:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Classes (between the lines)

A
it has to derive from another class called MonoBehaviour
which is automatically put there for you when you first create a script.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Classes (between the lines)

A
In Unity, if you create a custom class, like in the example below, you have to ask it to serialize it. 
This means that it will be converted into simple data that Unity can look at in the inspector. 
When you do that, it’ll see that you have the class will appear in the inspector.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly