0% found this document useful (0 votes)
19 views3 pages

Unity C# Functions Overview Guide

The document lists common Unity C# functions along with brief descriptions of their purposes. Functions include lifecycle methods like Awake(), Start(), and Update(), as well as input handling, physics interactions, and transformation methods. It serves as a quick reference for developers working with Unity scripts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Unity C# Functions Overview Guide

The document lists common Unity C# functions along with brief descriptions of their purposes. Functions include lifecycle methods like Awake(), Start(), and Update(), as well as input handling, physics interactions, and transformation methods. It serves as a quick reference for developers working with Unity scripts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

All Common Unity C# Functions (with One-Line

Descriptions)
Awake() – Called when the script instance is being loaded.
Start() – Called before the first frame update only once.
Update() – Called once per frame to handle logic and input.
FixedUpdate() – Called at fixed intervals for physics updates.
LateUpdate() – Called after all Update functions have been called.
OnEnable() – Called when the object becomes enabled and active.
OnDisable() – Called when the behaviour becomes disabled.
OnDestroy() – Called when the object is destroyed.
OnApplicationQuit() – Called before the application quits.
OnApplicationPause() – Called when the application is paused or resumed.
OnCollisionEnter() – Called when a collider/rigidbody has begun touching another
rigidbody/collider.
OnCollisionStay() – Called once per frame for every collider/rigidbody that is touching another
collider/rigidbody.
OnCollisionExit() – Called when a collider/rigidbody stops touching another collider/rigidbody.
OnTriggerEnter() – Called when another collider enters the trigger.
OnTriggerStay() – Called once per frame for every collider that is touching the trigger.
OnTriggerExit() – Called when another collider leaves the trigger.
OnMouseDown() – Called when the user presses the mouse button over the Collider.
OnMouseUp() – Called when the user releases the mouse button over the Collider.
OnMouseEnter() – Called when the mouse enters the Collider.
OnMouseExit() – Called when the mouse is no longer over the Collider.
OnMouseOver() – Called every frame while the mouse is over the Collider.
OnAnimatorMove() – Called after Animator has finished processing its movements.
OnAnimatorIK() – Called for setting up animation inverse kinematics (IK).
OnDrawGizmos() – Used to draw gizmos in the Scene view for debugging.
OnDrawGizmosSelected() – Draw gizmos only when the object is selected.
OnGUI() – Called for rendering and handling GUI events.
Reset() – Reset script properties to default values when attached.
Instantiate() – Creates a clone of the specified object.
Destroy() – Removes a game object, component, or asset from the scene.
FindObjectOfType() – Finds an object of a specified type in the scene.
FindObjectsOfType() – Finds all active objects of a specified type.
GetComponent() – Returns the component of Type attached to the GameObject.
GetComponents() – Returns all components of Type attached to the GameObject.
GetComponentInChildren() – Returns the component in any children of the GameObject.
GetComponentInParent() – Returns the component in any parent of the GameObject.
AddComponent() – Adds a component of a specified type to the GameObject.
CompareTag() – Checks if a GameObject has a specific tag.
Invoke() – Calls a method on a delay.
InvokeRepeating() – Calls a method repeatedly with a specified delay.
CancelInvoke() – Cancels all Invoke calls on the MonoBehaviour.
IsInvoking() – Checks if Invoke is scheduled for the MonoBehaviour.
Coroutine StartCoroutine() – Starts a coroutine function.
StopCoroutine() – Stops a coroutine.
StopAllCoroutines() – Stops all coroutines running on this MonoBehaviour.
DontDestroyOnLoad() – Prevents a GameObject from being destroyed when loading a new
scene.
[Link]() – Loads a scene by name or index.
[Link]() – Returns the currently active scene.
[Link]() – Quits the application.
[Link]() – Loads a new level (deprecated, use SceneManager).
[Link] – Time since the last frame (for frame-rate independent movement).
[Link] – Scale at which time passes in the game.
[Link]() – Returns true while the user holds down the key identified by name.
[Link]() – Returns true during the frame the user starts pressing down the key.
[Link]() – Returns true during the frame the user releases the key.
[Link]() – Returns true while a virtual button is held down.
[Link]() – Returns true during the frame the virtual button is pressed.
[Link]() – Returns true during the frame the virtual button is released.
[Link]() – Returns the value of the virtual axis (e.g., 'Horizontal', 'Vertical').
[Link] – The current mouse position in pixel coordinates.
[Link] – Number of touches currently on the screen.
[Link]() – Returns object representing status of a specific touch.
[Link]() – Casts a ray and returns information about what was hit.
[Link]() – Returns all colliders touching or inside a sphere.
[Link]() – Applies a force to the Rigidbody.
[Link]() – Moves a Rigidbody to a position while respecting interpolation.
[Link]() – Rotates a Rigidbody to rotation while respecting interpolation.
[Link]() – Moves the transform in the direction and distance of translation.
[Link]() – Rotates the transform about an axis by angle degrees.
[Link]() – Rotates the transform to face a target position.
[Link]() – Set the parent of the transform.
[Link]() – Linearly interpolates between two vectors.
[Link]() – Interpolates between two rotations (quaternions).
[Link]() – Creates a rotation from Euler angles.
[Link]() – Linearly interpolates between two float values.
[Link]() – Restricts a value between a minimum and a maximum.
[Link]() – Returns the absolute value of f.
[Link]() – Returns the square root of f.
[Link]() – Returns f raised to the power p.
[Link]() – Returns the sine of angle f in radians.
[Link]() – Returns the cosine of angle f in radians.
[Link]() – Returns the tangent of angle f in radians.

Common questions

Powered by AI

SceneManager.LoadScene() provides more control and flexibility compared to Application.LoadLevel(). It allows loading scenes by name or index, facilitates asynchronous loading, and offers callbacks for better scene transition control. These enhancements streamline scene loading and state management .

Not using FixedUpdate() for physics can lead to inconsistent or non-deterministic physics behavior, especially with varying frame rates. FixedUpdate() runs at a consistent interval, ensuring stable physics calculations and collision detection by providing a uniform timestep .

Coroutines in Unity allow for execution over multiple frames, giving more control over flow than regular functions which complete in a single frame. They use 'yield' to pause execution and resume at the next frame or after a specified delay, enabling asynchronous operations like waiting for a condition or running a routine at intervals .

Quaternion.Lerp() provides smooth rotation by interpolating between two rotations, reducing risks of gimbal lock and ensuring continuous rotation without sudden jumps. Directly modifying Euler angles can lead to these issues, making Quaternion interpolation preferable in many rotational transitions .

OnCollisionEnter() is called when a collider/rigidbody starts touching another collider/rigidbody, handling physical interactions and impulses. OnTriggerEnter() activates when another collider enters a trigger, used for events without physical response, such as collecting items or activating zones .

Input.GetAxis() is used for smooth, analog-like control schemes, mapping input range from -1 to 1. It is essential for natural player movement, offering fluid transitions in speed or direction, and for camera control, adjusting perspectives seamlessly in real-time .

Rigidbody.AddForce() applies a force to a Rigidbody, enabling movement through physics simulation. Understanding force is crucial as it determines how objects accelerate, interact with others, and react to user inputs, affecting game dynamics like jumping or pushing .

Time.deltaTime represents the time elapsed since the last frame, which is crucial for making movements or animations consistent across different frame rates. By multiplying movement calculations by Time.deltaTime, developers ensure that objects move at a consistent speed regardless of the frame rate .

Awake() is called when the script instance is being loaded, useful for initializing variables or states before the game starts. Start() is called before the first frame update, and it's a good place to put initialization code that depends on other objects being initialized .

Mathf.Clamp() restricts a value within a specified range, preventing errors or unrealistic behavior, such as keeping a player's health between 0 and the maximum value. It ensures stability in gameplay systems, maintaining logical state progression and consistency .

You might also like