Practical 1 3D Practice
Practical 1 3D Practice
Mobile
Mobile Game
Game Development,
Development, BTech
BTech IT
IT Sem
Sem VII
VII
Unity and C#
Part A
PRACTICAL 1
3D Practice
Topics Learned: Unity settings, C# Scripts, 3D Objects, Identify Keyboard Input, Tags, Collider,
RigidBody, Scene Management-Text, Load new Scene.
Scenario: Create a 3D Project in Unity “MyProject1” for MAC and PC. This project should have a
plane on which a cube is placed. Add material to the plane and cube. Place a Sphere with
material above the cube at a distance and when the Project is Run the Sphere should fall on top
of the cube, when it collides a Text “Destroyed” should be displayed. Pressing Key “s” should
load a new scene.
Steps to be followed:
Open Unity Hub and under Projects create a new Project “MyProject1”.
Once the Project is opened in Unity, set the Layout as either 2 by 3 or create your own
layout.
1|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
Step3: Recognizing Mouse Click
Create a cube on plane (add material),
Add a script to cube,
Destroy the cube when mouse clicked on cube.
2|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
Step9: Detect Collision
Add Sphere on top of cube,
Add Component (Physics-Rigid Body) to Sphere,
Add tag “Enemy” to Sphere,
Destroy cube when sphere with tag “Enemy” falls on cube.
3|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
4|Page
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
Prog/Yr/Sem: MBA Tech IT/4th/7th Batch: 2
Date of Experiment: 20/07/2021 Date of Submission:
1. Program: (Write Topics Learned, Scenario, Paste your program code (C# Scripts), Project
Window, Inspector Window of Plane, Sphere, Cube object).
Topics Learned: Unity settings, C# Scripts, 3D Objects, Identify Keyboard Input, Tags, Collider,
RigidBody, Scene Management-Text, Load new Scene.
Scenario: Create a 3D Project in Unity “MyProject1” for MAC and PC. This project should have a
plane on which a cube is placed. Add material to the plane and cube. Place a Sphere with
material above the cube at a distance and when the Project is Run the Sphere should fall on top
of the cube, when it collides a Text “Destroyed” should be displayed. Pressing Key “s” should
load a new scene.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CubeScript : MonoBehaviour
{
Rigidbody rb;
float xInput;
float zInput;
public float abc;
public GameObject WinningText;
// Start is called before the first frame update
5|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
void Start()
{
Debug.Log("Project Started");
//Destroy(gameObject,4f);
rb = GetComponent <Rigidbody>();
WinningText.SetActive(false);
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Debug.Log("Key Pressed");
//rb.AddForce(Vector3.up * 250f);
rb.velocity = Vector3.forward * 10f;
}
if(Input.GetKeyDown(KeyCode.S))
{
SceneManager.LoadScene("Scene1");
}
xInput=Input.GetAxis("horizontal");
zInput=Input.GetAxis("vertical");
rb.AddForce(xInput * abc, 0f, zInput * abc);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
WinningText.SetActive(true);
} } }
Project Window:
6|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
7|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
8|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
9|Page
Mobile Game Development, BTech IT Sem VII
Unity and C#
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 made the following observations:
The Cube and Sphere objects fall through the Plane unless they have Rigidbody
component added to them.
C# script written for Cube object must be manually added to the Cube using Add
Component for the script to work.
If the object moves past the plane that it is resting on, it can fall off of it and fall
through the floor.
Giving colour to any object requires creating a Material which must also be
manually added to the object using Add Component.
Unity can register mouse clicks and key presses using OnMouseDown and
GetKeyDown respectively as each keyboard key has its own name in Unity.
For force and velocity to be added to an object, Vector3 must be mentioned in
the code to specify the amount of force or velocity being added.
4. Conclusion (Learning Outcomes): How were the outcomes defined for the experiment in
Part A fulfilled through the scenario (Write on each Learning Outcome)?
10 | P a g e
Mobile Game Development, BTech IT Sem VII
Unity and C#
After successful completion of the practical, I was able to make the following
conclusions:
11 | P a g e