Quiz: Create with Code 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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?

GetComponent("Player");

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); } }

Hello: PlayerFrank

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); }

Input.GetButtonDown("Fire1")

Which of the following is NOT true about data types?

It is easier to increase the size of an array at runtime than it is for lists.

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;

Line 2 - the array

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.

Line 3 is not true

What would be the result of the following code? public class ExampleClass : MonoBehaviour { void Start() { SceneManager.LoadScene(Random.Range(0, SceneManager.sceneCount)); } }

Load a random scene from all currently loaded scenes

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"); }

Medium

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?

OnTriggerEnter

Which of the following is NOT true about variable modifiers?

Protected variables can only be accessed from static classes.

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> { } }

True

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?

When the user clicks a button, store the level number as a public integer variable, then load the loading scene. In the loading scene, use a Coroutine to delay the loading of the level using that integer variable.

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()); }

"Test" will appear after 5 seconds and will continue to appear every 5 seconds after that.

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"); }

1, 2

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; }

float FindMax(float num1, float num2)

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; }

int number return

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

setFloat("Speed_f", 0.3f);

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); }

string item in strings

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; } }

switch (dialogue)

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?

transform.Translate(Vector3.up, 90f);


Set pelajaran terkait

Lab 11 Connect- the spinal cord and spinal nerves

View Set

Neurodevelopmental Disorders in Children

View Set

heart- cardiac conduction system/ purkinje system

View Set

supply chain exam 2 chapter 3 test

View Set