[go: up one dir, main page]

0% found this document useful (0 votes)
5 views23 pages

Unity Answer

The document consists of multiple code snippets and questions related to Unity programming, specifically focusing on Entity Component System (ECS), naming conventions, method declarations, and collision detection. Each section requires the reader to determine whether the code adheres to ECS principles or Unity naming conventions, as well as to complete code snippets based on given requirements. The document serves as an assessment tool for understanding Unity's coding practices and functionalities.

Uploaded by

96 CK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views23 pages

Unity Answer

The document consists of multiple code snippets and questions related to Unity programming, specifically focusing on Entity Component System (ECS), naming conventions, method declarations, and collision detection. Each section requires the reader to determine whether the code adheres to ECS principles or Unity naming conventions, as well as to complete code snippets based on given requirements. The document serves as an assessment tool for understanding Unity's coding practices and functionalities.

Uploaded by

96 CK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

For each code snippet, select True if it is using ECS or False if it is not.

Note: You will receive partial credit for each correct answer.

Fals
Code Snippet True
e

using Unity.Jobs;
using Unity.Burst;
using Unity.Mathematics;
using UnityEngine;

public class EntityData : MonoBehaviour {


// ...
}

using System;
using UnityEngine;
using Unity.Entities;

[Serializable]
public struct EntityData :
IComponentData {
// ...
}

using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;

public struct EntityData :


IComponentData {
// ...
}
For each code snippet, select True if it is using ECS or False if it is not.

Note: You will receive partial credit for each correct answer.

Fals
Snippet True
e

using UnityEngine;
using System.Collections;

public class Boulder : MonoBehaviour


{
public Rigidbody boulderPrefab;
public Transform boulderPosition;
public float boulderSpeed;
}

using Unity.Entities;
using UnityEngine;

public class PowerupComponent : MonoBehaviour


{
public float hitPoints;
public Entity entity;
}

using Unity.Entities;
using UnityEngine;

public class EnemyProjectileSystem :


ComponentSystem
{
public Rigidbody rigidbody;
public InputComponent inputComponent;
}
For each code snippet, select True if it is using ECS
or False if it is not.

Note: You will receive partial credit for each correct


answer.

Tru Fals
Code Snippet
e e

using UnityEngine;
using System.Collections;

public class Fireball : MonoBehaviour


{
public Rigidbody fireballPrefab;
public Transform firePosition;
public float fireballSpeed;
}

using Unity.Entities;
using UnityEngine;

public class ShieldComponent : MonoBehaviour


{
public float Protection;
public float Size;
}
For each code snippet, select True if it is using ECS or False if it is not.

Note: You will receive partial credit for each correct answer.

Fals
Code Snippet True
e

using Unity.Entities;
using UnityEngine;

public class KeyboardComponent :


MonoBehaviour
{
public float Horizontal;
public float Vertical;
}

using UnityEngine;
using System.Collections;

public class KeyboardScript :


MonoBehaviour
{
public class Wizard
{
public Wizard() {}
}
}

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour


{
public float speed;
public float turnSpeed;

void Update()
{
Movement();
}
}
For each code snippet, select True if it is using Unity
naming conventions or False if it is not.

Note: You will receive partial credit for each correct


answer.

Tru Fals
Code Snippet
e e

public class Enemy :


MonoBehaviour {
private float Hitpoints;
void Start () {
Hitpoints = 50;
}
}

public class Enemy :


MonoBehaviour {
private float hitpoints;
void Start () {
hitpoints = 50;
}
}

public class enemy :


MonoBehaviour {
private float hitPoints;
void Start () {
hitPoints = 50;
}
}
For each code snippet, select True if it is using Unity
naming conventions or False if it is not.

Note: You will receive partial credit for each correct


answer.

Tru Fals
Code Snippet
e e

public class playerScript : Monobehaviour


{
public light playerLight;
void playerfunction ()
{
playerlight.Enabled = !
playerlight.Enabled;
}
}

Public Class playerScript :


MonoBehaviour
{
Public Light PlayerLight;
void PlayerFunction ()
{
PlayerLight.Enabled = !
PlayerLight.Enabled;
}
}

public class PlayerScript : MonoBehaviour


{
public Light playerLight;
void PlayerFunction ()
{
playerLight.Enabled = !
playerLight.Enabled;
Tru Fals
Code Snippet
e e

}
}

For each code snippet, select True if it is using Unity


naming conventions or False if it is not.

Note: You will receive partial credit for each correct


answer.

Answer Area
Tru Fals
Code Snippet
e e

public class PlaySoundEffect : MonoBehaviour {

public AudioSource enteringSound;


public AudioSource leavingSound;

private void ontriggerenter(Collider Other)


{
if (Other.CompareTag("Player"))
{
PlaySound(enteringSound);
}
}

private void OnTriggerExit(Collider other)


{
if (other.CompareTag("Player"))
{
PlaySound(leavingSound);
}
}
Create a method named OrbitSun that meets the following
requirements:

 is only available within the Orbiter class


 invokes the ChangeRotationSpeed defined in
the Orbiter class

Complete the code by selecting the correct options from the drop-
down lists.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Orbiter : MonoBehaviour


{
public GameObject sun;
private int speed;

// Update is called once per frame


void Update()
{
OrbitSun(speed);
}

// OrbitSun is a method that will rotate


an object around a sun object
private void OrbitSun(int
rotationSpeed)
{

transform.RotateAround(sun.transform.position,
Vector3.up, rotationSpeed * Time.deltaTime);
ChangeRotationSpeed(4);
}

// ChangeRotationSpeed is a method that


will change the speed of the orbit
public void ChangeRotationSpeed(int
changeSpeed)
{
speed = speed + changeSpeed;
}
}

Given the following code example, determine what the


appropriate data type is to declare the variable rb in order
to avoid a "Cannot implicitly convert type" error.

Select the correct answer from the drop-down list.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour


{
public Vector3 teleportPoint;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
rb.MovePosition(transform.position +
transform.forward * Time.deltaTime);
}
}

Given the incomplete if statements, use the


correct Input Method to make the statements log the
correct message to the console. Select the correct options
in the drop-down lists.

Note: You will receive partial credit for each correct


answer.

void Update()
{
if (Input.GetKey (KeyCode.LeftArrow))
{
Debug.Log("Left Arrow key is being held
down");
}

if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("Up Arrow key was pressed once");
}

if (Input.GetKeyUp(KeyCode.DownArrow))
{
Debug.Log("Down Arrow key was released");
}
}

Read the class provided below. Then create the correct


method declaration for a method that would accept the
arguments provided in the code and set the text variable of
a Text object.

Complete the code by selecting the correct options from the


drop-down lists.
using UnityEngine;
using UnityEngine.UI;

public class UnlockGate : MonoBehaviour


{
public Text textToDisplay;

private void OnTriggerEnter(Collider other)


{
if
(other.gameObject.CompareTag("Gate"))
{
other.gameObject.SetActive(false);

SetMessageToDisplay("Congratulations! You have


unlocked the gate!");
}
else
{
gameObject.SetActive(false);
SetMessageToDisplay("Unfortunately
you have broken your key. You tried to unlock
something other than a gate.");
}
}

Private void
SetMessageToDisplay(string stringToDisplay)
{
textToDisplay.text = stringToDisplay;
}
}

The given code clip includes a function that needs to be called in an


animation event. But the function isn't being called at run-time,
when the animation plays.

Fix the error by selecting the correct options from the drop-down
lists.
Answer Area
using UnityEngine;

public class monotest : MonoBehaviour


{
public Transform footLeft;
public Transform footRight;
public ParticleSystem footEffect;

private void Start()


{
footEffect = GetComponent<ParticleSystem>();
}

// An event trigger for each foot. 1 - left foot, 2 - right foot.

public void FootLandEffect(int foot)


{
if (foot == 1 && footEffect.isStopped)
{
footEffect.gameObject.transform.position =
footLeft.position;
}
else if (foot == 2 && footEffect.isStopped)
{
footEffect.gameObject.transform.position =
footRight.position;
}
footEffect.Play();
}
To answer this question, use the AddForce API that accepts
a Vector value and a numerical value.

You need to apply a force value to a Rigidbody that is


attached to a GameObject. The force must move the object
in the direction it is facing. You must use a force value that
can be set in the inspector.

Complete the code by selecting the correct options from the


drop-down lists.

Answer Area

public class MovingThings : MonoBehaviour


{
private float speedOfMotion;
public float speedForce;
private static float forceSpeed = 10f;
private Rigidbody rigidbody;

void Start()
{
speedOfMotion = 10f;
rigidbody =
gameObject.GetComponent<Rigidbody>();
}

void FixedUpdate()
{
rigidbody.AddForce(transform.forward * speedForce
);
}
}
Use the following information from the API documentation
to answer this question.

[Beginning of API documentation]

Material.SetColor();

Declaration

public void SetColor(string name, Color value);

Parameters

name Property name, e.g. "_Color"

value Color value to set.

Description

Sets a named color value.

[End of API documentation]

Complete the code by selecting the correct options from the


drop-down lists.

Answer Area

material.SetColor( “_Color” , Color.red


);
Which function will continue to be called as long as it is
colliding with any other collider?

Complete the script below by selecting the correct options


from the drop-down list.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour


{
AudioSource audioSource;

void Start()
{
audioSource =
GetComponent<AudioSource>();
}

void OnCollisionStay (Collision collision)


{
foreach (ContactPoint contact in
collision.contacts)
{
Debug.DrawRay(contact.point,
contact.normal, Color.white);
}

if
(collision.relativeVelocity.magnitude > 2)
{
audioSource.Play();
}
}
}

You might also like