Unity
Code
Sprite Animation
Scene Manager
Game Accessibility
100

What component gives a GameObject its gravity and mass?

RigidBody

100

How would you detect if the player presses the "Space" key and triggers a jump with physics?

Use Input.GetKeyDown and apply a force using Rigidbody2D:


[SerializeField] private Rigidbody2D rb;

[SerializeField] private float jumpForce = 5f;

void Update() {

    if (Input.GetKeyDown(KeyCode.Space))

    {

        rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);

    }

}


100

What Unity component is used to manage sprite animations for a 2D game object?

The Animator component is used to manage sprite animations, often in combination with an Animation Controller and animation clips.

100

How do you load a specific scene by name in Unity?

Use SceneManager.LoadScene("SceneName"); where "SceneName" is the name of the scene you want to load. Ensure the scene is added to the Build Settings.

100

What Unity UI feature can be used to make text easier to read for players with visual impairments?

Unity provides features like TextMeshPro, which allows text to be rendered with high clarity. You can also adjust font size, contrast, and colors to improve readability.

200

How do you detect collisions between two GameObjects in Unity?

Use the OnCollisionEnter or OnTriggerEnter methods in a script attached to one of the GameObjects. Ensure both objects have Colliders, and at least one has a RigidBody.

200

How can you make a UI button call a method in a script?

  1. Add a Button component to the UI object.
  2. Create a public method in your script:
public void OnButtonClick() {
    Debug.Log("Button Clicked!");
}


200

How do you create a basic frame-by-frame sprite animation in Unity for a 2D character?

  1. Select your sprite sheet in the Unity Editor.
  2. In the Inspector, set the Sprite Mode to Multiple and use the Sprite Editor to slice the sheet into individual frames.
  3. Drag the sliced frames into the Scene or the Project window to automatically create an Animation Clip.
  4. Assign the generated animation clip to an Animator component attached to the GameObject.
200

How can you check if a specific scene is currently loaded in Unity?

You can check using SceneManager.GetActiveScene().name to get the name of the active scene and compare it with the desired scene name.

200

How can you implement colorblind-friendly design in Unity, ensuring all players can distinguish between important visual elements?

You can use colorblind-friendly palettes or patterns to differentiate UI elements. Additionally, implement toggles in the settings menu for players to select specific colorblind modes (e.g., protanopia, deuteranopia) and apply shaders to adjust colors dynamically.

300

How would you make a GameObject perform a repeated action (ex: scaling, moving, or spawning) at a specific time interval in Unity?

You can use the InvokeRepeating method or a coroutine with a WaitForSeconds delay.

300

How do you spawn an enemy every 2 seconds at a random position within a defined area?

Use InvokeRepeating or a Coroutine:

[SerializeField] private GameObject enemyPrefab;

[SerializeField] private Vector2 spawnAreaMin;

[SerializeField] private Vector2 spawnAreaMax;


void Start() {

    InvokeRepeating(nameof(SpawnEnemy), 2f, 2f);

}

void SpawnEnemy() {

    float x = Random.Range(spawnAreaMin.x, spawnAreaMax.x);

    float y = Random.Range(spawnAreaMin.y, spawnAreaMax.y);

    Vector2 spawnPosition = new Vector2(x, y);

    Instantiate(enemyPrefab, spawnPosition, Quaternion.identity);

}

300

How can you programmatically switch between two sprite animations (e.g., "Idle" and "Running") based on player input?

  • Use parameters in the Animator Controller to control transitions between animations.
  • In a script, use Animator.SetBool(), Animator.SetTrigger(), or similar methods to change the parameters.
  • using UnityEngine;


    public class CharacterAnimation : MonoBehaviour {

        private Animator animator;


        void Start() {

            animator = GetComponent<Animator>();

        }


        void Update() {

            float horizontal = Input.GetAxis("Horizontal");


            if (horizontal != 0) {

                animator.SetBool("isRunning", true);

            }

            else {

                animator.SetBool("isRunning", false);

            }

        }

    }

300

How do you load a new scene additively so that it overlays the current scene without unloading it?

Use SceneManager.LoadScene("SceneName", LoadSceneMode.Additive);

300

How can Unity’s Input System be adapted to support players with limited mobility who rely on alternative input devices, such as a single-button controller?

Unity’s Input System allows you to remap controls. To support single-button controllers, you can design mechanics where multiple actions are context-sensitive or based on holding and releasing the button for varying durations. Use the Input Action asset to map different actions to a single button.

400

How do you use Unity's Animator Controller to trigger animations?

  • Create an Animator Controller and assign it to the GameObject's Animator component.
  • Add animation clips to the Animator Controller.
  • Use parameters (e.g., bool, int) to control transitions between animations.
  • Trigger animations in a script using Animator.SetBool() or similar methods.
400

How would you implement a singleton pattern for a GameManager class in Unity to ensure only one instance exists throughout the game and persists across scenes?

public class GameManager : MonoBehaviour {

    public static GameManager Instance { get; private set; }


    void Awake() {

        if (Instance != null && Instance != this)

        {

            Destroy(gameObject); // Destroy duplicate

            return;

        }

        Instance = this;

        DontDestroyOnLoad(gameObject); // Persist across scenes

    }

}


400

How do you blend two sprite animations (e.g., "Running" and "Jumping") to play simultaneously using the Animator in Unity?

You can use Animator Layers to blend animations:

  1. Open the Animator window and create a new layer in the Layers tab.
  2. Assign the "Jumping" animation to the new layer.
  3. Adjust the layer's Weight to control how much the "Jumping" animation influences the final animation.
  4. Use scripts to manage parameters for both layers to blend them dynamically.
400

How would you handle persistent objects (e.g., a Game Manager) across multiple scenes without reloading them when switching scenes?

Use DontDestroyOnLoad() to make an object persist between scenes. Attach the script to the object you want to persist.

Example:

void Awake() {

    DontDestroyOnLoad(gameObject);

}


400

How would you implement audio cues in Unity to assist visually impaired players with navigation and gameplay feedback?

You can use Unity’s AudioSource component to play spatialized audio cues. Attach AudioSources to objects to provide positional audio feedback. For example:

  • Use stereo panning to indicate direction.
  • Trigger sounds when a player approaches an interactive object.
  • Implement haptic feedback in conjunction with audio for additional guidance.
500

How would you implement persistent data in Unity to save the player's score, settings, or other game data and be loaded even after the game is closed and reopened?

PlayerPrefs is a quick and simple way to save and load small amounts of data, such as settings or scores.

500

What is a delay method in Unity, and how would you implement it to make a game object perform an action (ex: change its color) after a delay of 3 seconds? Provide an example.

A delay method in Unity is often used to pause the execution of a specific action for a certain amount of time. This is commonly achieved using Coroutines and the WaitForSeconds method. Delay methods are used for scenarios like:

  • Delaying visual or gameplay effects.
  • Waiting before restarting a level or showing UI elements.
  • Sequencing events in gameplay.
500

How would you implement a system to smoothly transition between multiple sprite animations based on speed and direction using Blend Trees in Unity?

  • In the Animator, create a Blend Tree.
  • Set up parameters (e.g., Speed and Direction).
  • Add multiple animations to the Blend Tree (e.g., Idle, Walk, Run) and assign them thresholds.
  • Write a script to dynamically update the Blend Tree parameters:
  • using UnityEngine;


    public class CharacterBlendTree : MonoBehaviour {

        private Animator animator;


        void Start() {

            animator = GetComponent<Animator>();

        }


        void Update() {

            float speed = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).magnitude;

            float direction = Mathf.Atan2(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal")) * Mathf.Rad2Deg;


            animator.SetFloat("Speed", speed);

            animator.SetFloat("Direction", direction);

        }

    }

500

How would you implement a loading screen that displays progress while transitioning between two scenes?

Use an Async Operation to load the next scene in the background while displaying progress on a UI element.

Example:

using UnityEngine;

using UnityEngine.SceneManagement;

using UnityEngine.UI;


public class LoadingScreen : MonoBehaviour {

    public GameObject loadingScreen;

    public Slider progressBar;


    public void LoadSceneWithProgress(string sceneName) {

        StartCoroutine(LoadSceneAsync(sceneName));

    }


    private IEnumerator LoadSceneAsync(string sceneName) {

        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);


        // Activate loading screen

        loadingScreen.SetActive(true);


        while (!operation.isDone) {

            // Update progress bar

            float progress = Mathf.Clamp01(operation.progress / 0.9f);

            progressBar.value = progress;


            yield return null;

        }


        // Deactivate loading screen after loading is complete

        loadingScreen.SetActive(false);

    }

}


500

Describe how you would create and test a dynamic subtitles system in Unity to ensure accessibility for players with hearing impairments.      

  1. Create Subtitles System:

    • Use Unity's UI system to create a Text or TextMeshPro element.
    • Script the system to display subtitles dynamically during gameplay based on game events or audio.
    • Synchronize subtitles with audio using timestamps or cues in an event-driven system.
  2. Dynamic Scaling:

    • Allow players to resize and reposition subtitles in the settings menu.
  3. Testing for Accessibility:

    • Test readability by using high-contrast text and backgrounds.
    • Include color-coded text for different speakers.
    • Ensure subtitles accurately convey all dialogue and sound effects.

Example:

public class SubtitlesManager : MonoBehaviour {

    public TextMeshProUGUI subtitleText;


    public void DisplaySubtitle(string subtitle, float duration) {

        StartCoroutine(ShowSubtitle(subtitle, duration));

    }


    private IEnumerator ShowSubtitle(string subtitle, float duration) {

        subtitleText.text = subtitle;

        yield return new WaitForSeconds(duration);

        subtitleText.text = "";

    }

}


M
e
n
u