0
0
Unityframework~10 mins

Player spawning in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a public GameObject variable named playerPrefab.

Unity
public class GameManager : MonoBehaviour {
    public [1] playerPrefab;
}
Drag options to blanks, or click blank then click option'
Aint
BGameObject
Cstring
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or string instead of GameObject.
Forgetting to make the variable public.
2fill in blank
medium

Complete the code to instantiate the playerPrefab at the origin with no rotation.

Unity
void SpawnPlayer() {
    Instantiate(playerPrefab, [1], Quaternion.identity);
}
Drag options to blanks, or click blank then click option'
Anew Vector3(1, 1, 1)
BVector3.one
Ctransform.position
DVector3.zero
Attempts:
3 left
💡 Hint
Common Mistakes
Using Vector3.one which is (1,1,1) instead of the origin.
Using transform.position which may not be the origin.
3fill in blank
hard

Fix the error in the code to correctly spawn the playerPrefab inside Start().

Unity
void Start() {
    [1](playerPrefab, Vector3.zero, Quaternion.identity);
}
Drag options to blanks, or click blank then click option'
AInstantiate
BSpawn
CCreate
DNew
Attempts:
3 left
💡 Hint
Common Mistakes
Using Spawn or Create which are not valid Unity methods.
Using New which is a keyword but not a method.
4fill in blank
hard

Fill both blanks to spawn the playerPrefab at a random position on the XZ plane with Y=0.

Unity
void SpawnRandomPlayer() {
    Vector3 randomPos = new Vector3(Random.Range([1], [2]), 0, Random.Range(-10, 10));
    Instantiate(playerPrefab, randomPos, Quaternion.identity);
}
Drag options to blanks, or click blank then click option'
A-10
B0
C10
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 and 20 which shifts the spawn area.
Using the same value for min and max.
5fill in blank
hard

Fill all three blanks to spawn the playerPrefab with a random rotation around the Y axis.

Unity
void SpawnPlayerWithRotation() {
    Quaternion randomRotation = Quaternion.Euler(0, [1], 0);
    Vector3 spawnPos = new Vector3([2], 0, [3]);
    Instantiate(playerPrefab, spawnPos, randomRotation);
}
Drag options to blanks, or click blank then click option'
ARandom.Range(0, 360)
B0
C5
DRandom.Range(-5, 5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using fixed rotation instead of random.
Using non-zero spawn positions when not needed.