Consider this simple Unity C# script attached to a 2D GameObject. What will be printed in the console when the game starts?
using UnityEngine; public class TestScript : MonoBehaviour { void Start() { Vector2 position = new Vector2(3, 4); Debug.Log($"Position magnitude: {position.magnitude}"); } }
Recall the formula for the magnitude of a vector: sqrt(x² + y²).
The magnitude of Vector2(3,4) is sqrt(3*3 + 4*4) = sqrt(9 + 16) = sqrt(25) = 5.
Which of the following reasons best explains why starting with 2D is easier for new Unity developers?
Think about the complexity of physics and art assets in 2D vs 3D.
2D projects are simpler because they use simpler physics (like Rigidbody2D) and 2D sprites, which are easier to create and manage than 3D models.
This script is supposed to move a 2D character left and right using arrow keys. What is the error that prevents movement?
using UnityEngine; public class PlayerMovement : MonoBehaviour { public float speed = 5f; private Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { float move = Input.GetAxis("Horizontal"); rb.velocity = new Vector2(move * speed, rb.velocity.y); } }
Check the type of velocity expected by Rigidbody2D.
Rigidbody2D.velocity expects a Vector2, but the code assigns a Vector3, which causes incorrect behavior.
Choose the correct syntax to declare a public variable for a 2D sprite in a Unity script.
Look for the correct Unity class name for 2D sprites.
The correct class for 2D sprites in Unity is 'Sprite'. Texture2D is for textures, not sprites. Sprite2D does not exist.
This code creates a list of Vector2 positions for a 2D grid of size 3x3. How many items does the list contain after running?
using System.Collections.Generic; using UnityEngine; public class GridCreator { public List<Vector2> CreateGrid() { List<Vector2> positions = new List<Vector2>(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { positions.Add(new Vector2(x, y)); } } return positions; } }
Count how many times the inner loop runs for each outer loop iteration.
The outer loop runs 3 times (x=0,1,2), and for each, the inner loop runs 3 times (y=0,1,2), so total items = 3*3 = 9.