0
0
Unityframework~10 mins

Instantiating objects at runtime 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 instantiate a prefab at the origin with no rotation.

Unity
Instantiate(prefab, [1], Quaternion.identity);
Drag options to blanks, or click blank then click option'
Atransform.position
BVector3.zero
Cnew Vector3(1, 1, 1)
DQuaternion.Euler(0, 0, 0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a rotation value instead of a position.
Using transform.position which may not be the origin.
2fill in blank
medium

Complete the code to instantiate a prefab at the player's position.

Unity
Instantiate(prefab, [1], Quaternion.identity);
Drag options to blanks, or click blank then click option'
Aplayer.transform.position
BVector3.one
Cnew Vector3(0, 0, 0)
Dtransform.rotation
Attempts:
3 left
💡 Hint
Common Mistakes
Using Vector3.one which is (1,1,1) not the player's position.
Using transform.rotation instead of position.
3fill in blank
hard

Fix the error in the code to instantiate a prefab with the same rotation as the spawner object.

Unity
Instantiate(prefab, transform.position, [1]);
Drag options to blanks, or click blank then click option'
AQuaternion.identity
Btransform.position
CVector3.zero
Dtransform.rotation
Attempts:
3 left
💡 Hint
Common Mistakes
Using position instead of rotation.
Using Quaternion.identity which resets rotation.
4fill in blank
hard

Fill both blanks to instantiate a prefab at a random position within a range and with no rotation.

Unity
Vector3 randomPos = new Vector3(Random.Range(-10, 10), 0, [1]);
Instantiate(prefab, randomPos, [2]);
Drag options to blanks, or click blank then click option'
ARandom.Range(-5, 5)
BRandom.Range(-10, 10)
CQuaternion.identity
Dtransform.rotation
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform.rotation which applies spawner rotation.
Using a fixed number instead of Random.Range for position.
5fill in blank
hard

Fill all three blanks to instantiate a prefab, set its parent to the spawner, and name it "SpawnedObject".

Unity
GameObject obj = Instantiate([1], transform.position, [2]);
obj.transform.parent = [3];
obj.name = "SpawnedObject";
Drag options to blanks, or click blank then click option'
Aprefab
Btransform.rotation
Ctransform
Dplayer
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting the parent correctly.
Using player instead of transform for parent.
Using Quaternion.identity instead of spawner rotation.