0
0
Unityframework~20 mins

Player spawning in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Player Spawning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this player spawn position code?

Consider this Unity C# code snippet that sets a player's spawn position. What will be the printed position?

Unity
using UnityEngine;

public class SpawnTest : MonoBehaviour {
    void Start() {
        Vector3 spawnPos = new Vector3(5, 0, 10);
        Debug.Log($"Spawn position: {spawnPos}");
    }
}
ASpawn position: (0.0, 0.0, 0.0)
BSpawn position: (10.0, 0.0, 5.0)
CSpawn position: (5, 0, 10)
DSpawn position: (5.0, 0.0, 10.0)
Attempts:
2 left
💡 Hint

Look at how Vector3.ToString() formats the output with decimals.

🧠 Conceptual
intermediate
2:00remaining
Which method correctly instantiates a player prefab at a spawn point?

You have a player prefab and a spawn point in your scene. Which code snippet correctly creates the player at the spawn point's position and rotation?

AInstantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
BplayerPrefab = Instantiate(spawnPoint.position, spawnPoint.rotation);
CInstantiate(playerPrefab); playerPrefab.transform.position = spawnPoint.position;
DplayerPrefab.transform.position = spawnPoint.position; Instantiate(playerPrefab);
Attempts:
2 left
💡 Hint

Instantiate requires the prefab and the position and rotation as parameters.

🔧 Debug
advanced
2:00remaining
Why does the player not appear at the spawn point?

Given this code, the player does not appear at the spawn point as expected. What is the cause?

Unity
public GameObject playerPrefab;
public Transform spawnPoint;

void SpawnPlayer() {
    playerPrefab.transform.position = spawnPoint.position;
    Instantiate(playerPrefab);
}
AInstantiate is missing the rotation parameter.
BThe position is set on the prefab asset, not the instantiated object.
CspawnPoint is not assigned in the inspector.
DThe playerPrefab is null.
Attempts:
2 left
💡 Hint

Think about what happens when you change the prefab's transform before instantiating.

📝 Syntax
advanced
2:00remaining
Which code snippet correctly declares and uses a spawn method?

Identify the code snippet that compiles without errors and correctly spawns a player GameObject.

Avoid Spawn() { Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation, null); }
Bvoid Spawn() { Instantiate(playerPrefab, spawnPoint.position); }
Cvoid Spawn() { Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation); }
Dvoid Spawn() { Instantiate(playerPrefab); spawnPoint.position = playerPrefab.transform.position; }
Attempts:
2 left
💡 Hint

Instantiate requires either 1 or 3 parameters for position and rotation.

🚀 Application
expert
3:00remaining
How to ensure player respawns at last checkpoint after death?

You want the player to respawn at the last checkpoint reached. Which approach correctly stores and uses the checkpoint position?

AStore checkpoint position in a Vector3 variable and use Instantiate(playerPrefab, checkpointPosition, Quaternion.identity) on respawn.
BSet playerPrefab.transform.position to checkpoint position before Instantiate.
CUse PlayerPrefs to save checkpoint GameObject and Instantiate it on respawn.
DDestroy playerPrefab and create a new spawnPoint GameObject at checkpoint.
Attempts:
2 left
💡 Hint

Think about storing position data separately from prefab and using it on respawn.