C# in Unity Flashcards

1
Q

What is a life cycle component?

A

A method attached to a game object that is called automatically as part of the GAME life cycle

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

What methods are considered life cycle components?

A

Awake()

OnEnable()

Start()

FixedUpdate()

Update()

LateUpdate()

OnDisable()

OnDestroy()

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

What is the Awake() method and how is it used?

A

Awake()
Initializes variables or game state.
Called when the script instance is loaded

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

What is the OnEnable() method used for and when is it called?

A

OnEnable()
Use: Used to reset variables, states, or register for events like triggering a quest or objective.
When Called: When the object becomes enabled and active.

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

What is the Start() method used for and when is it called?

A

Start()
Use: Sets up references between scripts, initializes game logic, or starts coroutines.
When Called: Before the first frame update if the script is enabled.

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

What is the FixedUpdate() used for and when is it called?

A

FixedUpdate()
Use: Handles physics calculations, such as applying forces or adjusting rigidbody positions.
When Called: At a fixed frequency, independent of frame rate.

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

What is the Update() method used for and when is it called?

A

Update()
Use: Main function for frame-dependent logic, such as receiving input, moving objects, or triggering game events.
When Called: Once per frame.

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

What is the LateUpdate() method used for and when is it called?

A

LateUpdate()
Use: Executes code that needs to run after all Update() functions, such as camera follow scripts.
When Called: Once per frame, after Update().

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

What is the OnDisable() method used for and when is it called?

A

Use: Unregister from events, stop coroutines, or reset game logic.
When Called: When the script is disabled or the object it’s attached to is deactivated.

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

What is the OnDestroy() method used for and when is it called?

A

OnDestroy()
Use: Cleans up resources, saves state, or performs any necessary cleanup before the object is destroyed.
When Called: When the MonoBehaviour will be destroyed, either because the associated GameObject is being destroyed, or because the MonoBehaviour is being removed

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

What is the purpose of a Using.name; statement?

A

To reference a class, allowing access to its methods and components
Example: using UnityEngine;

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

What is MonoBehaviour and what is it use for?

A

It is a base class integrated with Unity to run all the life cycle functions along with added features.

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

What is a member variable and how is it used?

A

It’s a partial description of a class object. Member variables store data for different parts of the class and can be named anything but need the “type” of member variable being used example: int score =100;
Can be public or private.

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

What is the type “int” and how is it used?

A

Member variable to store whole numbers without decimal places. Example: int score = 100

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

What is the type “float” and how is it used?

A

Member variable that stores an imprecise number with decimal places, commonly used for “speed, strength etc..”

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

What is the type “bool” and how is it used?

A

Member variable that stores only true or false values, commonly used for toggles, flags and other binary state functions.

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

What is the type “string” and how is it used?

A

Member variable that stores a string of characters or text, commonly used for names, info blocks etc..

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

What is a life cycle?

A

The order in which the components and methods of the program are called.

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

What is the type “char” and how is it used?

A

Member variable that stores a single character. Less common but can be used to parse individual characters from strings.

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

What is type “double” and how is it used?

A

Similar to a float but with double the precision. Not often used in Unity due to performance issues.

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

What is type “decimal” and how is it used?

A

Member variable that stores a number with decimals. High precision, commonly used in financial calculations but not often used in Unity.

22
Q

What is type “byte” and how is it used?

A

Member variable that represents an 8-bit signed integer. Can be used for small numerical values to save memory.

23
Q

What is type “sbyte” and how is it used?

A

Member variable that represents an 8-bit signed integer that allows positive and negative values. Can be used for small numerical values to save memory.

24
Q

What is type Vector, how many types are there and how are they used?

A

Member variables. Can be Vector 2, 3, or 4. Used for positions, directions, and dimensions in space.

25
Q

What is type Quaternion and how is it used?

A

Member variable representing rotation. Used instead of Euler angles to avoid gimbal lock.

26
Q

What is type GameObject and how is it used?

A

Member variable representing the literal game object, example: a sword, food item, potion.
Used to call gameObjects into the class.

27
Q

What is type transform and how is it used?

A

Member variable representing the position, rotation and scale of a game object in the scene.
Used when handling movement, spawns etc..

28
Q

What is an “Attribute?”

A

an “attribute” is a special keyword that you place above classes, methods, or variables to specify how they should behave in certain contexts. Attributes can control various aspects of how your code interacts with the Unity engine and editor.

29
Q

What is [Serialized Field] and how is it used?

A

Attribute that Allows private fields to be serialized and visible in the Unity Inspector.

30
Q

What is [HideInInspector] and how is it used?

A

Attribute that Hides public fields from the Unity Inspector.

31
Q

What is [Range(min, max)] and how is it used?

A

Attribute that Restricts a numerical field in the Inspector to a specified range and provides a slider for it.

32
Q

What is [ToolTip(“text”)] and how is it used?

A

Attribute that Adds a tooltip that appears when you hover over a field in the Inspector.

33
Q

What is [Header(“text”)] and how is it used?

A

Attribute, Adds a header above fields in the Inspector.

34
Q

What is [Space(height)] and how is it used?

A

Attribute, Adds vertical space in the Inspector between fields.

35
Q

What is [ContextMenu(“MethodName”)] and how is it used?

A

Attribute, Adds a context menu item to a component’s gear icon in the Inspector, which calls the specified method when selected.

36
Q

What is [RequireComponent(typeof(ComponentType))] and how is it used?

A

Attribute, Automatically adds required components as dependencies.

37
Q

What is [ExecuteInEditMode] and how is it used?

A

Attribute, Makes a script execute in edit mode, not just play mode.

38
Q

What is [ContextMenu(“ItemName”)] and how is it used?

A

Attribute, Adds a function to the context menu of the component in the Inspector.

39
Q

What is [HelpURL(“URL”)] and how is it used?

A

Attribute, Links to a web page from the component’s Inspector window.

40
Q

What is [Multiline] and how is it used?

A

Attribute, Allows for multi-line string input in the Inspector.

41
Q

What is [TextArea(minLines, maxLines)] and how is it used?

A

Attribute, Similar to Multiline but with control over the min and max lines.

42
Q

What is the difference between a primitive and Struct member variables?

A

Primitive member variable do not reference a class and so store small data.
Struct member variables are a reference to a class and so have access to their own methods and member variables as well.

43
Q

What is an Access Modifier?

A

An Attribute of a property that controls access to that property from outside the class.

Public
Private
protected
internal
protected internal
private protected

44
Q

What is the public access modifier used for?

A
  • Accessible from any other class
  • Use for variables you need to access from other scripts or want to expose in the Unity Inspector
45
Q

What is the Private access modifier used for?

A
  • Only accessible within the same class
  • Use for variables that should not be accessible from other scripts
46
Q

What is the protected access modifier used for?

A
  • Accessible within the same class and derived classes
  • Use for variables that should be available to any subclass
47
Q

What is the internal access modifier used for?

A
  • Accessible only within the same assembly (usually the same project)
  • Use for variables that should be limited to the project scope
48
Q

What is the protected internal access modifier used for?

A
  • Accessible within the same assembly and from derived classes in any assembly
  • Use for variables that should be protected but still available to subclasses anywhere
49
Q

What is the private protected access modifier used for?

A
  • Accessible within the same class and derived classes in the same assembly
  • Use for variables that need strict access control but should be available to subclasses
50
Q

What is Time.deltaTime and how is it used

A

Time refers to a Unity class with “.” referencing that it will use the following component from that class.
deltaTime is a class that allows the computer to track the time between frames, this allows the computer to display a smooth real-time effect instead of each frame.

51
Q

What is an if statement and how is it used?

A

An if statement is a fundamental control structure in programming that evaluates a condition and executes a block of code if the condition is true.