Skip to main content

2nd quiz


Question 1

If it says, “Hello there!” in the console, what was the code used to create that message?


Debug(“Hello there!”);


Debug.Log("Hello there!");


Debug.Console(“Hello there!”);


Debug.Log(Hello there!);


Question 2

If you want to destroy an object when its health reaches 0, what code would be best in the blank below?



Select image to expand


health > 0


health.0


health < 1


health < 0


Question 3

The code below creates an error that says, “error CS1503: Argument 1: cannot convert from 'UnityEngine.GameObject[]' to 'UnityEngine.Object'”. What could you do to remove the errors?



Select image to expand


A. On line 1, change “GameObject[]” to “GameObject”


B. On line 1, change “enemyPrefabs” to “enemyPrefabs[0]”


C. On line 3, change “Start()” to “Update()”


D. On line 5, change “enemyPrefabs” to “enemyPrefabs[0]”


Either A or D


Both A and D together


Both B and C together


Question 4

Which comment best describes the following code?



Select image to expand


// If player collides with another object, destroy player


// If enemy collides with another object, destroy the object


// If player collides with a trigger, destroy trigger


// If player collides with another object, destroy the object


Question 5

If you want to move the character up continuously as the player presses the up arrow, what code would be best in the two blanks below:



Select image to expand


GetKey(KeyCode.UpArrow)


GetKeyDown(UpArrow)


GetKeyUp(KeyCode.Up)


GetKeyHeld(Vector3.Up)


Question 6

Read the documentation from the Unity Scripting API and the code below. Which of the following are possible values for the randomFloat and randomInt variables?



Select image to expand

-----





Select image to expand

-----





Select image to expand


randomFloat = 100.0f; randomInt = 0;


randomFloat = 100.0f; randomInt = 100;


randomFloat = 50.5f; randomInt = 100;


randomFloat = 0.0f; randomInt = 50.5;


Question 7

You are trying to randomly spawn objects from an array. However, when your game is running, you see in the console that there was an “error at Assets/Scripts/SpawnManager.cs:5. IndexOutOfRangeException: Index was outside the bounds of the array.” Which line of code should you edit in order to resolve this problem and still retain the random object functionality?



Select image to expand


Line 2


Line 3


Line 4


Line 5


Question 8

If you have made changes to a prefab in the scene and you want to apply those changes to all prefabs, what should you click?





Select image to expand


The “Create” or "+" drop-down at the top of the Hierarchy


The “Open” button at the top of the Inspector


The “Overrides” drop-down at the top of the Inspector


The “Add Component” button at the bottom of the Inspector


Question 9

Read the documentation from the Unity Scripting API below. Which of the following is a correct use of the InvokeRepeating method?



Select image to expand


InvokeRepeating(“Spawn, 0.5f, 1.0f”);


InvokeRepeating(“Spawn”, 0.5f, 1.0f);


InvokeRepeating(“Spawn", gameObject, 1.0f);


InvokeRepeating(0.5f, 1.0f, “Spawn”);


Question 10

You’re trying to create some logic that will tell the user to speed up if they’re going too slow or to slow down if they’re going too fast. How should you arrange the lines of code below to accomplish that?



Select image to expand


4, 6, 1, 2, 5, 9, 7, 8, 3

void Update() { if (speed < 10) {Debug.Log(speedUp); } else if (speed > 60) { Debug.Log(slowDown); } } private float speed; private string slowDown = "Slow down!"; private string speedUp = "Speed up!";




6, 1, 2, 5, 7, 8, 3, 4, 9

if (speed < 10) { Debug.Log(speedUp); } else if (speed > 60) { Debug.Log(slowDown); } private float speed; private string slowDown = "Slow down!"; private string speedUp = "Speed up!"; void Update() { }




7, 8, 3, 4, 6, 5, 2, 1, 9

private float speed; private string slowDown = "Slow down!"; private string speedUp = "Speed up!"; void Update() { if (speed < 10) { Debug.Log(slowDown); } else if (speed > 60) { Debug.Log(speedUp); } }




7, 8, 3, 4, 6, 1, 2, 5, 9

private float speed; private string slowDown = "Slow down!"; private string speedUp = "Speed up!"; void Update() { if (speed < 10) { Debug.Log(speedUp); } else if (speed > 60) { Debug.Log(slowDown); } }