Name:     ID: 
 
Email: 

C# in Unity Final Exam

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

Which of the following do you think makes the most sense for a simple movement state machine?
mc001-1.jpg
a.
Image A
c.
Image C
b.
Image B
 

 2. 

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?
mc002-1.jpg
a.
4, 6, 1, 2, 5, 9, 7, 8, 3
c.
7, 8, 3, 4, 6, 5, 2, 1, 9
b.
6, 1, 2, 5, 7, 8, 3, 4, 9
d.
7, 8, 3, 4, 6, 1, 2, 5, 9
 

 3. 

Which of the following is the correct way to declare a new List of game objects named “enemies”?
mc003-1.jpg
a.
Line 3
c.
Line 1
b.
Line 2
d.
Line 4
 

 4. 

When you run a project with the code below, you get the following error: “NullReferenceException: Object reference not set to an instance of an object.” What is
most likely the problem?
mc004-1.jpg
a.
The Player object does not have a collider
c.
The “Start” method should actually be “Update”
b.
. The Enemy object does not have a Rigidbody component
d.
There is no object named “Player” in the scene
 

 5. 

The code below produces “error CS0029: Cannot implicitly convert type 'float' to 'UnityEngine.Vector3'”. Which of the following would remove the error?
mc005-1.jpg
a.
On line 1, change “Vector3” to “float”
c.
Either On line 1, change “Vector3” to “float” OR On line 3, change “=” to “+”
b.
On line 3, change “=” to “+”
d.
None of the options
 

 6. 

Which of the following is most likely the condition for the transition between “Run” and “Walk” shown below?
mc006-1.jpg
a.
Jump_b is true
c.
Speed_f is Greater than 0.5
b.
Speed_f is Less than 0.5
d.
Animation_int is Less than 10
 

 7. 

Read the Unity documentation below about the OnMouseDrag event and the code beneath it. What will the value of the “counter” variable be if the user clicked and held down the mouse over an object with a collider for 10 seconds?
mc007-1.jpg
a.
1
d.
100
b.
A value over 100
e.
0
c.
99
 

 8. 

Look at the documentation and code below. Which of the following lines would NOT produce an error?
mc008-1.jpg
a.
Line 6
c.
Line 5
b.
Line 7
d.
Line 8
 

 9. 

Which comment best describes the following code?
mc009-1.jpg
a.
// If player collides with another object, destroy player
c.
// If player collides with a trigger, destroy trigger
b.
// If enemy collides with another object, destroy the object
d.
// If player collides with another object, destroy the object
 

 10. 

You are trying to STOP spawning enemies when the player has died and have created the two scripts below to do that. However, there is an error on the underlined code, “isAlive” in the EnemySpawner script. What is causing that error?
mc010-1.jpg
a.
The “p” should be capitalized in “playerController.isAlive”
c.
The if-statement cannot be in the Update method
b.
The “bool” in the PlayerController class needs a “public” access modifier
d.
“isAlive” must start with a capital “I” (“IsAlive”)
 

 11. 

What best describes the difference between the below images, where the car is in the second image is further along the road?
mc011-1.jpg
a.
The second car’s X location value is higher than the first car’s
c.
The second car’s Z location value is higher than the first car’s
b.
The second car’s Y location value is higher than the first car’s
d.
The second car’s Transform value is higher than the first car’s.
 

 12. 

The following message was displayed in the console: “Monica has 20 dollars”. Which of the line options in the PrintNames function produced it?
mc012-1.jpg
a.
Option A
c.
Option C
b.
Option B
d.
Option D
 

 13. 

Read the documentation from the Unity Scripting API below. Which of the following is a correct use of the InvokeRepeating method?
mc013-1.jpg
a.
InvokeRepeating(“Spawn, 0.5f, 1.0f”);
c.
InvokeRepeating(“Spawn", gameObject, 1.0f);
b.
InvokeRepeating(“Spawn”, 0.5f, 1.0f);
d.
InvokeRepeating(0.5f, 1.0f, “Spawn”);
 

 14. 

The code below produces the error, “error CS0029: Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Rigidbody'”. What could be done to fix
this issue?
mc014-1.jpg
a.
On line 1, change “collision” to “Rigidbody”
c.
On line 3, delete “.gameObject”
b.
On line 2, change “gameObject” to “Rigidbody”
d.
. On line 3, add “.GetComponent<Rigidbody>()” before the semicolon
 

 15. 

If you want to destroy an object when its health reaches 0, what code would be best in the blank below?
mc015-1.jpg
a.
health > 0
c.
health < 1
b.
health.0
d.
health < 0
 

 16. 

If you wanted a button to display the message, “Hello!” when a button was clicked, what code would you use to fill in the blank?
mc016-1.jpg
a.
(SendMessage);
c.
(SendMessage(Hello));
b.
(SendMessage(“Hello”));
d.
(SendMessage(string Hello));
 

 17. 

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?
mc017-1.jpg
a.
On line 1, change “GameObject[]” to “GameObject”
e.
Either On line 1, change “GameObject[]” to “GameObject” or On line 5, change “enemyPrefabs” to “enemyPrefabs[0]”
b.
On line 1, change “enemyPrefabs” to “enemyPrefabs[0]”
f.
Both On line 1, change “GameObject[]” to “GameObject” and On line 5, change “enemyPrefabs” to “enemyPrefabs[0]” together
c.
On line 3, change “Start()” to  Update()”
g.
Both On line 1, change “enemyPrefabs” to “enemyPrefabs[0]” and On line 3, change “Start()” to  Update()” together
d.
On line 5, change “enemyPrefabs” to “enemyPrefabs[0]”
 

 18. 

Which of these is the correct way to get a reference to an AudioSource component on a GameObject?
mc018-1.jpg
a.
Line A
c.
Line C
b.
Line B
d.
Line D
 

 19. 

Which of the following variables would be visible in the Inspector?
mc019-1.jpg
a.
speed
c.
speed & turnSpeed
b.
turnSpeed
d.
horizontalInput & forwardInput
 

 20. 

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?
mc020-1.jpg
a.
randomFloat = 100.0f;
randomInt = 0;
c.
randomFloat = 50.5f;
randomInt = 100;
b.
randomFloat = 100.0f;
randomInt = 100;
d.
randomFloat = 0.0f;
randomInt = 50.5;
 

 21. 

Given the animation controller / state machine below, which code will make the character transition from the “Idle” state to the “Walk” state?
mc021-1.jpg
a.
setFloat(“Speed_f”, 0.3f);
c.
setTrigger(“Speed_f”);
b.
setInt(“Speed_f”, 1);
d.
setFloat(“Speed_f”, 0.1f);
 

 22. 

Which Unity window contains a list of all the game objects currently in your scene?
a.
Scene view
c.
Hierarchy
b.
Project window
d.
Inspector
 

 23. 

If there is a boolean in script A that you want to access in script B, which of the following are true:
mc023-1.jpg
a.
3 and 4 only
d.
1, 2, and 3 only
b.
2 and 3 only
e.
1 and 2 only
c.
All are true
f.
1 only
 

 24. 

If it says, “Hello there!” in the console, what was the code used to create that message?
a.
Debug(“Hello there!”);
c.
Debug.Console(“Hello there!”);
b.
Debug.Log("Hello there!");
d.
Debug.Log(Hello there!);
 

 25. 

You’re trying to write some code that creates a random age between 1 and 100 and prints that age, but there is an error. What would fix the error?
mc025-1.jpg
a.
Change line 1 to “private float age”
c.
On line 7, change the word “private” to “void”
b.
Add the word “int” to line 8, so
it says “int age = …”
d.
Add a new line after line 8 that says “return age;”
 

 26. 

You run your game and get the following error message in the console, “NullReferenceException: Object reference not set to an instance of an object”. Given the image and code below, what would resolve the problem?
mc026-1.jpg
a.
In the hierarchy, rename “Game Manager” to “gameManager”
c.
In the hierarchy, rename “Game Manager” as “GameManager”
b.
On Line 3, remove the GetComponent code
d.
On Line 1, rename “GameManager” as “Game Manager”
 

 27. 

Which of the following statements about functions/methods are correct:
mc027-1.jpg
a.
A and B are correct
d.
Only D is correct
b.
Only B is correct
e.
None are correct
c.
B and C are correct
 

 28. 

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?
mc028-1.jpg
a.
The “Create” drop-down at the top of the Hierarchy
c.
The “Overrides” drop-down at the top of the Inspector
b.
The “Open” button at the top of the Inspector
d.
The “Add Component” button at the bottom of the Inspector
 

 29. 

By default, what will be the first state used by this Animation Controller?
mc029-1.jpg
a.
“Any State”
c.
“Death”
b.
“NotCrouched”
d.
“Crouch_Up”
 

 30. 

Which comment would best describe the code below?

horizontalInput = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.up, horizontalInput);
a.
// Rotates around the Y axis based on left/right arrow keys
c.
// Rotates in an upward direction based on left/right arrow keys
b.
// Rotates around the Z axis based on up/down arrow keys
d.
// Moves object up/down based on the the left/right arrow keys
 

 31. 

The image below shows the preferences window that allows you to change which script editing tool (or IDE) you want to use. Where would you click to choose an alternative code editing tool?
mc031-1.jpg
a.
The red box
c.
The green box
b.
The blue boc
 

 32. 

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?
mc032-1.jpg
a.
Line 1
c.
Line 4
b.
Line 3
d.
Line 5
 

 33. 

Which of the following follows Unity’s naming conventions (especially as it relates to capitalization)?
mc033-1.jpg
a.
Line A
c.
Line C
b.
Line B
d.
Line D
 

 34. 

You are trying to create a new method that takes a number and multiplies it by two. Which method would do that?
mc034-1.jpg
a.
Method A
c.
Method C
b.
Method B
d.
Method D
 

 35. 

What is true about the following two lines of code?
mc035-1.jpg
a.
They will both move an object at the same speed
c.
They will both move an object along the same axis
b.
They will both move an object in the same direction
d.
They will both rotate an object, but along different axes
 

 36. 

Based on the code below, what will be displayed in the console when the button is clicked?
mc036-1.jpg
a.
“Welcome, firstName Smith”
c.
“Welcome + Robert + Smith”
b.
“Button is ready”
d.
“Welcome, Robert Smith”
 

 37. 

Which of the following conditions properly tests that the game is NOT over and the player IS on the ground
mc037-1.jpg
a.
Line A
c.
Line C
b.
Line B
d.
Line D
 

 38. 

Which of the following variable declarations observes Unity’s standard naming conventions (especially as it relates to capitalization)?
mc038-1.jpg
a.
2 and 4
c.
4 and 5
b.
3 and 6
d.
1 and 5
 

 39. 

Which comment best describes the code below?
mc039-1.jpg
a.
// If the player collides with an enemy, destroy the enemy
c.
// If the enemy collides with a spike, destroy the enemy
b.
// If the enemy collides with a spike, destroy the spike
d.
// If the player collides with a spike, destroy the spike
 

 40. 

Which of the following lines of code is using standard Unity naming conventions?
/* a */ Public Float Speed = 40.0f;
/* b */ public float Speed = 40.0f;
/* c */ Public float speed = 40.0f;
/* d */ public float speed = 40.0f;
a.
Line A
c.
Line C
b.
Line B
d.
Line D
 

 41. 

You are trying to assign the powerup variable in the inspector, but it is not showing up in the Player Controller component. What is the problem?
mc041-1.jpg
a.
You cannot declare a powerup variable in the Player Controller Script
c.
The powerup variable should be public instead of private
b.
You cannot assign GameObject type variables in the inspector
d.
The PlayerController class should be private instead of public
 

 42. 

Which of the following follows Unity naming conventions (especially as they relate to capitalization)?
mc042-1.jpg
a.
Line 1
c.
Line 3
b.
Line 4
d.
Line 2
 

 43. 

What is a possible value for the horizontalInput variable?
mc043-1.jpg
a.
-10
c.
“Right”
b.
0.52
d.
Vector3.Up
 

 44. 

In what order do you put the words when you are declaring a new variable?
public float speed = 20.0f;
a.
[data type] [access modifier][variable value] [variable name]
c.
[data type] [access modifier][variable name] [variable value
b.
[access modifier] [data type][variable name] [variable value]
d.
variable name] [data type][variable name] [data type]
 

 45. 

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:
mc045-1.jpg
a.
GetKey(KeyCode.UpArrow)
c.
GetKeyUp(KeyCode.Up)
b.
GetKeyDown(UpArrow)
d.
GetKeyHeld(Vector3.Up)
 

Completion
Complete each statement.
 

 46. 

What is the operator used in C# to output the remainder or Modulus?
 

 

 47. 

______________ is creating a reusable pool of objects that can be activated and deactivated rather than instantiated and destroyed, which is much more efficient.
 

 

 48. 

________________ is an attribute that allows protected access to derived classes.
 

 

 49. 

What is the Build type for projects to be uploaded and embedded online?
 

 

 50. 

_______________________ are Unity’s default methods that run in a very particular order over the life of a script.
 

 



 
         Start Over