Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile
Mobile Game
Game Development,
Development, BTech
BTech IT
IT Sem
Sem VII
VII

Unity and C#
Part A
PRACTICAL 2
2D Practice
Topics Learned: Unity settings, C# Scripts for Touch Device, 2D Sprite, RigidBody2D, Vector2 for
PlayerDirection.

Scenario: Create a 2D Project in Unity “Project2D_Practice” for Android Device. This project
should have 2D Sprite Square. Move the Sprite around using the arrow keys.

Learning Outcomes of Practical: Students would be able to


1. UnUnderstand the Unity Settings for Game Development.
2. Find and match the apt 2D components with required properties.
3. Apply Programming Concepts to make the Project interactive.

Steps to be followed:
 Open Unity Hub and under Projects create a new Project “Project2D_1”.
 Once the Project is opened in Unity, set the Layout as either 2 by 3 or create your own
layout.
 Android Settings:
o Select File Menu -> Build Settings
o Select Platform as Android (If Android platform does not exists then go to Unity
Hub and Install Android SDK & NDK Tools).
o Click on Player Settings Button and under Resolution and Presentation->“Default
Orientation as Portrait”. And “Scripting Backend as ILCPP” and check on ARM64.
o In the Game View select the Aspect as 16:9 Portrait.
 Import a Sprite by Create -> Sprite -> Square and rename the Sprite as Player.
 Either Run the Project on Game View or Device Simulator.
o For Selecting Device Simulator: Windows->Package Manager, Select Unity
Registry, Select the gear symbol for enabling Advanced Settings and enable
Preview Packages. This will now show “Device Simulator”. Install it.
 Add Rigidbody component to the Player Sprite with Freeze Rotation Z axis selected,
Gravity as zero. Create C# Script “Player.cs” and attach to the Player GameObject.
1|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#

2|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#
Part B
(to be completed by students)
(Students must submit the soft copy as per the following segments. The soft copy must be
uploaded on the Blackboard. The filename should be Batch_RollNo_Exp_No)
Roll No.: I057 Name: Siddharth Somesh
th th
Prog/Yr/Sem: MBA Tech IT/4 /7 Batch: 2
Date of Experiment: 27-07-2021 Date of Submission:

1. Program: (Write Topics Learned, Scenario, Paste your program code (C# Scripts), Project
Window, Inspector Window of Square Sprite).

Topics Learned: Unity settings, C# Scripts for Touch Device, 2D Sprite, RigidBody2D,
Vector2 for PlayerDirection.

Scenario: Create a 2D Project in Unity “Project2D_Practice” for Android Device. This


project should have 2D Sprite Square. Move the Sprite around using the arrow keys.

C# Script: Player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    Rigidbody2D rb;
    Vector2 playerDir;
    public float playerSpeed;

    // Start is called before the first frame update
    void Start()
    {
        rb=GetComponent <Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        float dirX=Input.GetAxisRaw("Horizontal");

3|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#
        float dirY=Input.GetAxisRaw("Vertical");
        playerDir=new Vector2(dirX, dirY);
        
    }
    void FixedUpdate() 
    {
        rb.velocity=new Vector2(playerDir.x*playerSpeed, playerDir.y*playerSpeed
);   
    }
}

Project Window:

Inspector Plane: Sprite Square

4|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#

2. Output: (Paste Output Screens of Game played on Android Device).

Start Screen:

5|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#

Moving Player with Arrow Keys:

3. Observations: A brief description of the design aspects and working of the code in your
own words.

After the successful completion of the practical, I was able to make the following
observations:

6|Page
Mobile Game Development, BTech IT Sem VII

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Mobile Game Development, BTech IT Sem VII

Unity and C#
 For a 2D project, each component being added must be a 2D component as well.
 Instead of objects, we make Sprites in 2D projects.
 Components like Rigidbody are named as Rigidbody2D for a 2D project.
 Instead of using Vector3, we used Vector2.
 FixedUpdate method can be used to define the velocity of the player and it will be
called once per frame.

4. Conclusion (Learning Outcomes): How were the outcomes defined for the experiment in
Part A fulfilled through the scenario (Write on each Learning Outcome)?

After the successful completion of the practical, I could make the following conclusions:
 Understood the Unity settings for 2D projects in Game Development.
 Understood how to find and apply the 2D components for the project.
 Understood how to utilise programming concepts with 2D constraints for a 2D
project.

7|Page

You might also like