C# in Unity Flashcards
What is a life cycle component?
A method attached to a game object that is called automatically as part of the GAME life cycle
What methods are considered life cycle components?
Awake()
OnEnable()
Start()
FixedUpdate()
Update()
LateUpdate()
OnDisable()
OnDestroy()
What is the Awake() method and how is it used?
Awake()
Initializes variables or game state.
Called when the script instance is loaded
What is the OnEnable() method used for and when is it called?
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.
What is the Start() method used for and when is it called?
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.
What is the FixedUpdate() used for and when is it called?
FixedUpdate()
Use: Handles physics calculations, such as applying forces or adjusting rigidbody positions.
When Called: At a fixed frequency, independent of frame rate.
What is the Update() method used for and when is it called?
Update()
Use: Main function for frame-dependent logic, such as receiving input, moving objects, or triggering game events.
When Called: Once per frame.
What is the LateUpdate() method used for and when is it called?
LateUpdate()
Use: Executes code that needs to run after all Update() functions, such as camera follow scripts.
When Called: Once per frame, after Update().
What is the OnDisable() method used for and when is it called?
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.
What is the OnDestroy() method used for and when is it called?
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
What is the purpose of a Using.name; statement?
To reference a class, allowing access to its methods and components
Example: using UnityEngine;
What is MonoBehaviour and what is it use for?
It is a base class integrated with Unity to run all the life cycle functions along with added features.
What is a member variable and how is it used?
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.
What is the type “int” and how is it used?
Member variable to store whole numbers without decimal places. Example: int score = 100
What is the type “float” and how is it used?
Member variable that stores an imprecise number with decimal places, commonly used for “speed, strength etc..”
What is the type “bool” and how is it used?
Member variable that stores only true or false values, commonly used for toggles, flags and other binary state functions.
What is the type “string” and how is it used?
Member variable that stores a string of characters or text, commonly used for names, info blocks etc..
What is a life cycle?
The order in which the components and methods of the program are called.
What is the type “char” and how is it used?
Member variable that stores a single character. Less common but can be used to parse individual characters from strings.
What is type “double” and how is it used?
Similar to a float but with double the precision. Not often used in Unity due to performance issues.