You are on page 1of 7

Institut Supérieur des Études Technologiques de Sousse

Code 2nd Level License in Informatics - Specialization: Multimedia and Web Development (MDW)

Exam Group : MDW 21


Preparation to the Unity Certification Date : January 2020
Teacher in charge M. Bassem SEDDIK Time : 1 hour 30 minutes
Number of pages 7 pages (6 pages to return + 1 annex) Documents Non Authorized

First Name : Correction N° Student card : ………………………………………….

Family Name : Sample N° Room : ………………. N° place : …………………



Exam: Preparation to the Unity Certification Mark /20
Code Notice: The Exam is in English, you can choose to answer in French if needed
I.Multiple choice questions: (6.5 pts) ………………..

Choose the one-and-only correct answer. Do not rewrite it, just indicate the couple (number, letter):
1) A 256px squared Sprite of a flying bird has 12 frames laid out with 3 frames Vertically
and 4 Horizontally. How to slice it correctly in the Sprite Editor?
A. Set Type to Grid By Cell Count Set Column & Row to C4 R3
B. Set Type to Grid By Cell Size Set Pixel Size to X64 Y84
C. Set Type to Grid By Cell CountSet Column & Row to C3 R4
D. Set Type to Grid By Cell SizeSet Pixel Size to X84 Y64
2) We have several city buildings that are textured and will not move in the Scene. In order
to optimize the draw calls of their textures, which Static option is to choose?
Surveillants A. Batching
Signatures B. Off-Mesh Links
……………… C. Lightmapping
……………… D. Navigation
……………… 3) We use Cinemachine to create Blend List Camera. We want to slowly ease out from the
……………… first Virtual Camera then linearly enter the second Virtual Camera. What Blend In setting is
………………
to use?
………………
A. Linear
………………
B. Cut
……………… C. Ease Out
……………… D. Hard In
……
4) Using Curves view in the Timeline Clip, we want to animate a bouncing ball from the
ground. Th e ball jumps and stands a bit on air then gets down. After
adding 3 keyframes to the Y position Curve, what Interpolation Mode
is to choose for keyframes to get the ball standing in the air?
Corrector A. Auto
Signature B. Flat
C. Clamped Auto
……………… D. Free Smooth
………………
5) We imported two fighters having animations attached to them. We need to use Mecanim
………………
to create some new animations for them. When importing their FBX files, which animation to
………………
choose?
……………….
A. Humanoid

B. None
C. Legacy
D. Generic

Page 1 of 7
Write Nothing In Here


6) We created a Blend Tree to control our D. Window > General > Services
character’s facial animations. We need to set 10) Using Cinemachine, we set up a Virtual
the weight of each node to a specific value. Camera for a 2D side scrolling game and want
Which Blend Type should the Artist use for the camera to only show the area delimited by
this Blend Tree? a given 2D Box Collider. What Virtual Camera
A. 2D Simple Directional to choose?
B. 2D Freeform Cartesian A. Cinemachine Impulse Listener
C. 1D B. Cinemachine Follow Zoom
D. Direct C. Cinemachine Collider
7) We have a script to change our D. Cinemachine Confiner
character’s animation according to his speed.
11) An Artist has set the Texture Type to
The speed is forwarded to a parameter called
CharacterSpeed on the characters Animator Sprite(2D and UI) in an images Import
Settings. What is the other setting that should
component, we play a different animation.
be set when preparing a Sprite Texture for 9-
What Parameter Type is to choose for
CharacterSpeed in the Animator? Slicing?
A. Set Mesh Type to Full Rect
A. Trigger B. Set Sprite Mode to Multiple
B. Bool C. Set Extrude Edges higher than 1
C. Int D. Set Pivot to Custom
D. Float 12) An Artist is adding a Canvas to hold
8) We are using Cinemachine to set up a some UI components for a VR application.
Virtual Camera for a game with a top down What Render Mode should the Artist use for
perspective view. The Virtual Camera should the best UI experience in VR?
be able to follow a moving car and accept A. Screen Space - Overlay
mouse input. To accomplish this, what should B. World Space
C. Screen Space - Camera
the Artist set the Virtual Cameras Body
property to? 13) We have a script that will display an
A. Framing Transposer animated Sprite of a key when the user
collides with a 3D model of a key in the scene.
B. Tracked Dolly
The user should not be able to click on or
C. Orbital Transposer interact with the Sprite. The script has a
D. Hard Lock To Target variable for the key Sprite. Then the Artist
9) We want to use Unity’s Cloud Build with needs to connect in the Inspector to a UI
Collaborate. What Window in the editor shoul component in the Hierarchy. What type of UI
we open in order to enable Cloud Build? component should the player use to
A. Window > Analysis > Profiler accomplish this?
A. Image
B. Window > Asset Management > Colab B. Button
History C. Canvas Renderer
C. Window > Package Manager D. Raw Image

Page 2 of 7
II. 3D programming of a game in Unity (12.5 pts)
We will create a game where a sleeping little boy (or girl)
that we control, will fight some toys using given arms. This
is a Survival Shooter game that take place in the child’s
room as given in the figure blow.

When playing, several 3D enemies “Hellaphent, ZomBear,


Zombunny et ZomClown” will follow our character (boy or
girl) and can cause damage to him (her). Some other ally
friend characters are the “dog and sheep”.

II.1. Script for the movement of our player using PC : (5pts)


Use and complete the given script afterwards in order to :
II.1.1. Define the links that the script has with different game objects in the scene
II.1.2. What does the highlighted instructions 1 et 2 allow to do?
II.1.3. What does the highlighted instructions 3 et 4 allow to do?
II.1.4. Add the instruction « GameManager.Instance » where necessary
II.1.5. What does the highlighted instruction 5 allow to do?
II.1.6. Add the instruction « playerMovement.transform.position » where necessary
II.1.7. What does the highlighted instructions 6 et 7 allow to do?

public class PlayerInputPC : MonoBehaviour


{
[SerializeField] PlayerMovement playerMovement = null;
[SerializeField] PlayerAttack playerAttack = null; Execute the underlying
[SerializeField] PauseMenu pauseMenu;
code only if one of the
void Reset () {//Grab the needed component references
platforms is detected
playerMovement = new PlayerMovement();
playerAttack = new PlayerAttack();
pauseMenu = FindObjectOfType<PauseMenu>();
}
#if UNITY_ANDROID || UNITY_IOS || UNITY_WP8 1 This instruction causes
void Awake() { the current instance
Destroy(this); 2 referenced by “this” to
}#endif be destroyed

void Update () {
if (pauseMenu != null && Input.GetButtonDown("Cancel")) A reference to a
pauseMenu.Pause(); function that hands the
if (!CanUpdate()) movement of the
return;
character
HandleMoveInput(); 3
HandleAttackInput(); 4
HandleAllyInput();
} A reference call to a
bool CanUpdate() { function that handles
if (pauseMenu != null && pauseMenu.IsPaused) the Attack behaviors
return false; for the character

Page 3 of 7
if (GameManager.Instance.Player == null || (GameManager.Instance.Player.transfor
m != transform)
return false;
return true; // the inverse case
}
void HandleMoveInput() {
if (playerMovement == null) Detects if the mouse
return; has been clicked and is
float horizontal = Input.GetAxisRaw("Horizontal"); in a valid location
float vertical = Input.GetAxisRaw("Vertical");
playerMovement.MoveDirection = new Vector3(horizontal, 0, vertical);
if (MouseLocation.Instance != null && MouseLocation.Instance.IsValid) { 5
Vector3 lookPoint = MouseLocation.Instance.MousePosition - …………………………………………………………
…… ;
playerMovement.LookDirection = lookPoint;
} Detects if the input
} type related to the
void HandleAttackInput() { “Fire” behavior has
if (playerAttack == null) been called in the
return; Unity engine
if (Input.GetButtonDown("SwitchAttack")){
playerAttack.SwitchAttack();
} Applies the Fire()
if (Input.GetButton("Fire1")){ 6 function relative to
playerAttack.Fire(); 7 the instance named
} “playerAttack()”
else if(Input.GetButtonUp("Fire1")) {
playerAttack.StopFiring ();
}
}
void HandleAllyInput() {
if (Input.GetButtonDown("SummonAlly") && (playerMovement.transform.position != nul
l)
(GameManager.Instance.SummonAlly();
}
}

II.2. Our Game Manager Script (5 pts)


II.2.1. What is the role of the 3 instructions [SerializeField], [Header] and
[HideInInspector] ?
They allow to show the private variables in the inspector, to add title to them and
hide those public, repetively
II.2.2. Why does the script declare its same name as static at the highlighted line 1?
II.2.3. What does the highlighted instruction 2 allow to do?
II.2.4. What is the goal from the tests made in the Awake() method?
Make sure that we have a singleton reference to one and only one instance of the GameManager class
II.2.5. What is the goal of the method UnSummonAlly()?
Hide the Ally characters after they have appeared for a while and set back the enemies to follow the
player
II.2.6. What is the goal of the method ReloadScene()?
Restart the current scene from the beginning one again
II.2.7. Complete all the instructions that are required.

Page 4 of 7
A static reference
public class GameManager : MonoBehaviour variable named
{ “Instance” a unique
variable for the
public static GameManager Instance; 1
“GameManager” class
[Header("Player and Enemy Properties")]
public PlayerHealth Player;
public Transform EnemyTarget;
[SerializeField] float delayOnPlayerDeath = 1f;
[Header("UI Properties")]
[SerializeField] Text infoText; // show info to player The GameObject is
[SerializeField] Text gameoverText; referenced by the private
[Header("Player Selection Properties")] variable “enemySpawner”
[SerializeField] GameObject enemySpawners; 2 in the code and is
[SerializeField] Animator cameraAnimator; visible in the inspector
[Header("Ally Properties")] thanks to the
“SerializeField” mention
[SerializeField] AllyManager allyManager;
int score = 0;
void Awake(){
if (Instance == null)
Instance = this;
else if (Instance != this)
Destroy(this);
}
public void PlayerChosen(PlayerHealth selected){
Player = selected;
EnemyTarget = Player.position;
if(infoText != null)
infoText.text = "A sample init Text";
if(enemySpawners != null)
enemySpawners. SetActive(true) ; // Among many other possible anwsers
if(cameraAnimator != null)
cameraAnimator. Play ("Start");
}
public void PlayerDied(){
EnemyTarget = null;
if(gameoverText != null)
gameoverText. enabled= true;
}
public void PlayerDeathComplete(){
Invoke("ReloadScene", delayOnPlayerDeath ); // this variable is predeclared
}
public void AddScore(int points){
score += 1;
if (infoText != null)
infoText.text = "Score: " + score.ToString();
if (allyManager != null)
allyManager.AddPoints(points);
}
public void SummonAlly(){
if (allyManager == null)
return;
Ally ally = allyManager.SummonAlly();
if (ally != null){
EnemyTarget = ally. position;
Invoke("UnSummonAlly", ally.Duration);
}
}

Page 5 of 7
void UnSummonAlly(){
EnemyTarget = Player. position;
allyManager.UnSummonAlly();
}
void ReloadScene(){
Scene currentScene = SceneManager.GetActiveScene();
SceneManager.LoadScene(currentScene );
}
}

II.3. Completing the enemies Spawning (dispersion) in the scene: (2.5 pts)

In our ZombieToys scene, we have placed a number of 3D empty gameObjects that will be used as points of
apparition for the enemies. Thys will be instantiated and spawned out of these positions. You are asked to complete
the following script in order to:

II.3.1. Create a number of instances variable named maxEnemies and another variable spawnRate that
controls the rate of their apparition in the scene.
II.3.2. Since the start of the game, create an array table that will hold the enemies list but they will be
deactivated and so, non-visible in the scene yet.
II.3.3. Make a loop on all the enemies and make them visible using the method SpawnEnemy
public class EnemySpawner : MonoBehaviour
{
[Header("Spawner Properties")]
[SerializeField] GameObject enemyPrefab;
[SerializeField] float spawnRate;
[SerializeField] int maxEnemies;
[Header("Debugging Properties")]
EnemyHealth[] enemies;

void Awake(){
enemies = new EnemyHealth[maxEnemies];

for (int i=0; i< enemies.length; i++)


{
Enemies[i].SetActive(false);
}
void SpawnEnemy(){
for (int i=0; i< enemies.length; i++)
{
//wait for a time lapse
Sleep(spawnRate);
//Set the next index of the table to be active
Enemies[i].SetActive(true);
}
}
}

All The Best of Work


Page 6 of 7
Annex: Unity help sheet

• Typcal Script C#
using UnityEngine;
using System.Collections;
public class BasicTargetMover : MonoBehaviour {
void Start () {// Initialization
}
void Update () {// Mise à jour de la scène
}
}

• Variables and basic Types


int i = 5; enum Directions {North, East, South,
float x = 0.1f; West};
bool isDone = false; Transform target;
string name = "Brian"; GameObject projectile;
int[] array1; Color c = new Color(255,0,0);

• Vectors
public Vector2 loc = new Vector2(float x, float y);
public Vector3(float x, float y, float z);
public Vector4(float x, float y, float z);

• 3D primitives
//Exemple de creation de Quad
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Quad);
//PRIMITIVES: Sphere, Capsule, Cylinder, Cube, Plane, Quad

• Components
//Ajout:
SphereCollider sc = gameObject.AddComponent<SphereCollider> ( ) as SphereCollider;
//Accès
HingeJoint hinge = gameObject.GetComponent<HingeJoint>();

• Transformations
//Exemple de modification de position:
transform.position = new Vector3(0, 0, 0);
//Modification de rotation en quaternions :
public void Rotate(Vector3 eulerAngles);
//Exemple de modification d’échelle:
transform.localScale += new Vector3(0.1F, 0, 0);

• Finding a GameObject in the scene


GameObject target = GameObject.Find(“Enemy”); // Par nom
GameObject target = GameObject.FindWithTag(“Player”); // Par Tag

• Instanciation
GameObject spawnedObject = Instantiate (prefabObject, spawnPosition, spawnRotation) as
GameObject;

• Reading predefined entries


bool x = Input.GetButtonDown(“Jump”); // Appui sur la touche Unity définie pour l’action
Jump
bool x = Input.GetKey(KeyCode.RightArrow); // Appui sur la touche « flèche droite » du
clavier
bool x = Input.GetMouseButtonDown(1); // Click sur le bouton 1 de la souris
float x = Input.GetAxis(“Horizontal”); // valeur du déplacement de la souris sur les X

Page 7 of 7

You might also like