Complete the code to create a 2D sprite in Unity.
GameObject sprite = new GameObject();
sprite.AddComponent<[1]>();In Unity, to display a 2D image, you add a SpriteRenderer component to a GameObject.
Complete the code to move a 2D object horizontally using the arrow keys.
float move = Input.GetAxis("Horizontal"); transform.Translate(move * [1] * Time.deltaTime, 0, 0);
The variable speed controls how fast the object moves horizontally.
Fix the error in the code to detect a 2D collision.
void OnCollisionEnter2D(Collision2D [1]) { Debug.Log("Collision detected"); }
The parameter name can be anything, but collision is commonly used and matches the method signature.
Fill both blanks to create a dictionary of 2D game objects with their names as keys.
Dictionary<string, GameObject> [1] = new Dictionary<string, GameObject>(); [2].Add("Player", playerObject);
The dictionary variable name must be consistent. Here, gameObjects is used both times.
Fill all three blanks to create a 2D vector, normalize it, and print its magnitude.
Vector2 direction = new Vector2([1], [2]); Vector2 normalized = direction.[3](); Debug.Log(normalized.magnitude);
The vector is created with (3,4), then normalized using Normalize() method.