Quiz: Create with Code 2

Quiz

Beginner

+180 XP

30m

Unity Technologies

Quiz: Create with Code 2 thumbnail

This quiz will assess your understanding of the concepts covered in the Create with Code 2 Mission.

Question 1

What debug message would be logged to the console if Random.Range returned a value of 8?

int randomInt = Random.Range(0,10);
if(randomInt <= 3)
{
   Debug.Log("Low");
}
else if(randomInt > 8)
{
   Debug.Log("High");
}
else
{
   Debug.Log("Medium");
}

Select only one

Question 2

Which of the following conditions would successfully print “Success”?

  1. if (true && !false) { print(“Success”); }
  2. if (true || false) { print(“Success”); }
  3. if (true && !true) { print(“Success”); }
  4. if (false || !true) { print(“Success”); }

Select only one

Question 3

What code should go in the blank below in order to make the console print “First String” “Second string” “Third string”?

string[] strings = new string[3];
 
strings[0] = "First string";
strings[1] = "Second string";
strings[2] = "Third string";
 
foreach (__________)
{
    print (item);
}

Select only one

Question 4

What will appear in the console if the following code is run?

void Start()
{
    StartCoroutine(MyCoroutine());
}

private IEnumerator MyCoroutine()
{
 yield return new WaitForSeconds(5);
    Debug.Log("Test");
   StartCoroutine(MyCoroutine());
}

Select only one

Question 5

What code would you use to fill in the blank in order to print “Incorrect dialogue value” to the console?

int dialogue = 3;

void Start()
{
   _______________
   {
      case 2:
         print("Goodbye, old friend");
         break;
      case 1:
         print("Hello there");
         break;
      default:
         print("Incorrect dialogue value");
         break;
   }
}

Select only one

Question 6

When the player object collides with a coin object, the coin object should instantly disappear without impacting the player object’s physics. Which event function should you use to detect the collision between these two objects in order to destroy the coin?

Select only one

Question 7

According to Unity’s scripting API, the following are valid options for the Component.GetComponent method:

public Component GetComponent(Type type);
public Component GetComponent(string type);

Which of the following would be a correct implementation of this method?

Select only one

Question 8

According to the Unity Scripting API, the following are valid options for the Transform.Translate method:

public void Translate(Vector3 translation);
public void Translate(Vector3 translation, Transform relativeTo);
public void Translate(float x, float y, float z);
public void Translate(float x, float y, float z, Transform relativeTo);

Which of the following method calls would result in an error?

Select only one

Question 9

Given the animation transition shown below, which code will make the character transition from the “Idle” state to the “Walk” state?

Select only one

Question 10

According to Unity’s Scripting API, the following is a valid option for the Input.GetButtonDown method:

public static bool GetButtonDown(string buttonName);

Let’s say you wanted to launch a projectile when the user presses the “Fire1” button, what would you put in the blank below:

public GameObject projectile;
void Update()
{
  if (__________) 
    Instantiate(projectile, transform.position, transform.rotation);
}

Select only one

Question 11

The script below is attached to the Player GameObject in the scene. What would be displayed in the Console as a result of the code below?

public class PlayerManager : MonoBehaviour
{
 string playerName = "Frank";
 void Start()
  {
    Debug.Log("Hello: " + gameObject.name + playerName);
  }
}

Select only one

Question 12

Which of the following is NOT true about data types?

Select only one

Question 13

Which of the following variables is NOT initialized correctly?

  1. List<GameObject> objectList = new List<GameObject>();
  2. GameObject[] objectArray = new GameObject[];
  3. Dictionary<string, GameObject> objectDict = new Dictionary<string, GameObject>();
  4. bool isTrue = true;

Select only one

Question 14

Which of the following is NOT true about variable modifiers?

Select only one

Question 15

What would be the result of the following code?

public class ExampleClass : MonoBehaviour
{
 void Start()
  {       
   SceneManager.LoadScene(Random.Range(0, SceneManager.sceneCount));
  }
}

Select only one

Question 16

In order to construct a method that takes a number and returns a duplicate of that number rounded to the nearest integer, what code would you put in the following blanks, in order of appearance:

_____ DuplicateNumber(float _____)
{
  number *= 2;
 int newNumber = Mathf.RoundToInt(number);
  _____ newNumber;
}

Select only one

Question 17

What should be the method declaration to fill in the blank below, which should return the higher of two imputed float values?

_____________________
{
 float result;
 if (num1 > num2)
    result = num1;
 else
    result = num2;
 return result;
}

Select only one

Question 18

You want to create a loading scene sequence that works as follows. On a level select screen, there are a number of buttons, each corresponding to a different level. When the user clicks a level, you want to bring up a new loading screen, which displays the level number you selected, and after 5 seconds loads the scene corresponding to that level. How would you implement this, at a high level?

Select only one

Question 19

Which of the following guidelines about the use of variables and methods is NOT true?

  1. Variable names should be longer and include complete words rather than being shorter (e.g. “int secondsElapsed” would be better than “int secElpsd”).
  2. Methods names should usually include a verb or action in them (e.g. “void GenerateRandomObject” would be better than “RandomObject”).
  3. Methods should usually do two or three things - if there are methods that only do one thing each, it makes sense to combine them.
  4. When naming booleans, use common words like ”is”, “has”, and “can” (e.g. “isRaining”, “hasStarted”, “canMove”) to indicate that it is a boolean.

Select only one

Question 20

True or False:

The code snippet below is using Unity’s Entity Component System (ECS) as opposed to the more standard object-oriented framework.

using System;
using Unity.Entities;

namespace Shooter.ECS
{
    [Serializable]
    public struct MoveSpeed : IComponentData
    {
        public float Value;
    }

    public class MoveSpeedComponent : ComponentDataWrapper<MoveSpeed> { }
}

Select only one

Submit answers

To calculate your score, submit your answers to the quiz. A passing score will mark this quiz complete.

Correct answers needed to pass

19/20

Retake allowed after

0 Mins