Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views41 pages

CAGD Record Batch1

The document is a lab record for the Computer Animation & Game Design Lab at Bapatla Engineering College, detailing exercises conducted by B.Tech students in the 6th semester during the academic year 2023-2024. It includes a list of experiments such as building a spaceship and a rocket using Maya, applying textures, and creating animations in Unity. Each experiment outlines specific steps and techniques used in the design process, emphasizing practical skills in 3D modeling and game design.

Uploaded by

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

CAGD Record Batch1

The document is a lab record for the Computer Animation & Game Design Lab at Bapatla Engineering College, detailing exercises conducted by B.Tech students in the 6th semester during the academic year 2023-2024. It includes a list of experiments such as building a spaceship and a rocket using Maya, applying textures, and creating animations in Unity. Each experiment outlines specific steps and techniques used in the design process, emphasizing practical skills in 3D modeling and game design.

Uploaded by

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

Bapatla Engineering College::Bapatla(Autonomous)

Department of Computer Science and Engineering

Lab Record
III / IV B. Tech.
Computer Animation & Game Design Lab
(20CSLJO03)
Bapatla Engineering College::Bapatla(Autonomous)
Department of Computer Science and Engineering

CERTIFICATE

Redg. No.-

Certified and bonafide Record work done by


________________________________________________ B.Tech (Computer Science &
Engineering) 6th Semester In ‘Computer Animation & Game Design Lab (20CSL603) during the
academic year 2023-2024.

Lecturer – in – charge Head of the Department


Date: Dept. of CSE
Index

S. No. Date Lab Page


Exercise No.

1 30/1/24 Build a spaceship with polygons in maya? 5-7


2 6/2/24 Build a Rocket with NURBS surfaces in maya? 8-9
3 9/2/24 Application of texture to the spaceship? 10-12
4 13/2/24 Export a 3D model from maya (.fbx file)? 13-13
5 20/2/24 Export a model from Z-Brush to maya? 14-14
6 23/2/24 Create a sprite sheet and its animation in unity? 15-15
7 27/2/24 Creation of basic transformation in unity using c script? 16-20
8 1/3/24 Building health bar and control values on it with c script? 21-25
9 16/3/24 Experiment with canvas object- creation of text box, buttons and control 26-27
them with c script?
10 30/3/24 Experiment with onCollisionEnter2D() and onCollisionExit2D() 28-30
methods in unity?
11 6/4/24 Controlling transitions in animator based on boolean and float variables? 31-34
12 13/4/24 implement camera following in unity with c script? 35-37
13 20/4/24 Creation of animated materials in unity? 38-39
14 27/4/24 Import 3D model into unity from maya? 40-40
15 4/5/24 Creation of 3D game in unity with multiple states? 41-41
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 1
1. Build a spaceship with polygons in maya?
Steps:
1.1 Starting the ship
This spaceship will be built starting with a simple polygonal cube .The Poly Faces will then be extruded
to create a more complex shape.
1 Place and position a primitive cube
Select Create->Polygon Primitives->Cube
2 Turn on backface culling
The Poly Faces that are facing away from the view are not displayed and cannot be selected
3 Select the two side faces of cube
Press the Shift key and Select the opposite facet handle
4 Extrude and scale Poly Faces
Select Polygons->Extrude
5 Add wing base
Press the g key to reactivate the Extrude tool and start a new extrusion
6 Extrude and shape wing
Press the g key. Click-drag on the blue Move handle. Click-drag on red Scale handle.
7 Add a top wing
Select the facet handle belonging to the top surface of the shape. Press the g key. Click-drag on red
Scale handle to create a long thin polygon centered in the top facet.
1.2 Air intake ports
In addition to extruding out, you can use the extrusion tool to push a polygonal facet into a surface to
create an opening. For the ship’s air intake ports, this technique will be used.
1 Create the front of the ports
Select the facet handle belonging to the side thruster port. Press the Shift key and Select the opposite
facet. Press the g key to re-evoke the Extrude tool and start a new extrusion.
2 Add a lip to the ports
To give the thruster a little bit of an edge, you will next create a little lip using the extrude tool.Press the
g key.
3 Extrude the hole
Press the g key.
Click-drag on blue Move handle to push this facet back deep into the spaceship
4 Add the rear thruster
Tumble the view around to see the back of the ship.Select the facet handle belonging to back facet of
the ship. Press the g key.
Repeat the steps used to create the front thruster ports to finish the back exhaust hole
1.3 The front cockpit
You can now continue to use the extrude tool to pull out a cockpit area for the spaceship.
1 Pick the front facet
Tumble around to see the front of the ship.
Select the facet handle belonging to front facet of the ship.
2 Extrude the front facet twice
Press the g key.
Click-drag on blue Move handle to pull this facet out.
Press the g key.
Page | 5
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Use blue Move handle to pull a second facet out.
3 Scale and rotate the facet
Use the green Scale handle to scale the front facet down.
Use the red Scale handle to scale this facet in.
Use the green Move handle to move this piece down
1.4 Creating a more organic look
1 Smooth the spaceship
Press F8 to go back to Select by Object Type mode
Select Edit Polygons -> Smooth.
2 Edit the extrude history
In the Channel box, Select the polyExtrudeFacet1 node.
Select the Show Manipulator Tool.The manipulator for the first extrusion is displayed.
Use the blue Move handle to move the extrude in towards the center.
Both the extrude history and smooth action update, as the exhaust ports become more narrow
3 Edit the smooth history
Select the polySmoothFacet1 input node in the Channel box.
Set Divisions to 2.
4 Add a lattice
Change to the Animation menu set.
Select Deform -> Create Lattice.
In the Channel box, set the following under the ffd1LatticeShape node:
S Divisions to 4;
T Divisions to 2;
U Divisions to 6.
5 Edit the lattice points
Press F8 to go into Select by Component Type mode
Turn on the Points selection mask.The Poly Faces selection mask should turned off.
In the Top view, use the Shift key and click-drag to Select the twelve control points near the tips of the
wings
6 Move the tail
In the Perspective view, Select the six control points closest to the tail.
7 Move the lower back edge down
In the Side view, Select the four control points at the back lower edge.
Move these points down.
8 Move the wings tips down
In the Front view, Select all the control points on the right and left sides of the lattice.
Move these points down
9 Curve the nose forward and down
In the Side view, Select the front two rows of control points.
Move these points forward and down.
1.5 Finishing the model
1 Delete history
Press F8 to go back to Select by Object Type mode.
Select the spaceship.
Select Edit ->Delete by Type ->History.
2 Rename the polymesh
Rename the polymesh polyShip.

Page | 6
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
3 Save the file
Select File -> Save Scene As...
Save the file as polyShip.

OUTPUT:

Page | 7
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Experiment 2
2. Build a Rocket with NURBS surfaces in maya?
Steps:

2.1 Rocket Body


The goal is to create a cylindrical body with a tip at the top and an opening at the bottom.
We switch to the side view where we will create the silhouette of our rocket using curves. In the status
bar, switch to Modeling mode and then select Create-> Curve Tools-> EP Curve Tool from the menu.
Insert a few points so that you get a curve similar to the one in the picture.With such a curve, we can
now create a revolved body by rotating the curve around the y-axis and thus forming the hull of our
rocket. We do this by using the Revolve tool. Select the curve (let it be green), then select Surfaces->
Revolve via the menus. The result is a grid of curves. If we switch back to perspective view we see that
we have really created a 3D object. Let's rename our object rocketBody
2.2 Rocket engine
In the next step, we will create the exhaust of the rocket engine. Similar to the construction of the body,
we will use the revolve function here as well. The procedure is the same, and the goal is to get a rocket
shape. We also change the name of this object to rocketExhaust.
We can now combine the body and exhaust of the rocket. Select the exhaust, press the [W] key to
activate move tool and move it so that it connects to the rocket frame. The easiest way to move the
exhaust is in the side view, as this is the best way to see when it is in the correct position
2.3 Connecting objects into groups
First, mark both objects by clicking and holding [LMB] to the left above the rocket frame and dragging
the lower part of the rocket exhaust to the right, or by clicking [LMB] on one object first, pressing and
holding the [Shift] key, and then clicking with [LMB] to another subject.
Now select Edit-> Group from the menu or press the [Ctrl + G] keys. We notice that the whole structure
now turns green, which tells us that the object is highlighted, and a new name appears in the channel
window, namely group1. We will also change this name to something more friendly, namely the
rocketBase.
The objects of the rocketExhaust and rocketBody are siblings.
2.4 Creating flaps
The rocket flaps will be made with the help of flattened cones, which will be further reshaped.
First, we move the current model of the rocket from the coordinate starting point so that we can create
one instance of the flap in it. From the menu, select Create-> NURBS Primitives-> Cone □ (click on the
box when selecting). This allows us to define the basic properties of the cone. Define the properties:
• Axis: Y
• Radius: 1.5
• Height: 3
we press Apply. This created a cone with the desired properties in the coordinate origin. We rename it
rocketFlap1.
This, of course, is not yet a flap, as it should be slightly twisted, smaller and flattened. Rotate it 120º
around the x-axis in the Channel Window. Then flatten it by scaling it in the same direction to 1/5 of the
original value by entering the value 0.2 in the Channel Window under the ScaleX attribute. The flaps
are slightly reduced in the y and z directions to a value of 0.75.
The wing is moved into the rocket so that the cone shell partially extends from the rocket and the
bottom is completely hidden as shown in the figure.
We want to make 5 more flaps and distribute them evenly around the rocket's hull. We will do this by
using the duplicate tool, which allows us to multiply the desired object as many times as we like. With
Page | 8
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
additional settings, we can achieve a special behaviour of the duplication function, which allows you to
place duplicates in the desired places.
2.5 Pivots
Before we start duplicating objects, let's look at where the pivots of individual objects are located. As
already mentioned, pivot points are reference points around which transformations operate.
2.6 Duplicating flaps
By default, the pivot of an individual object is at its center. In the case of a cone, this is in the center of
the base area. So if we want to multiply the cone around the center of the rocket, we have to move its
grip to the center of the rocket. This is done by moving to the view from above, pressing the [d] key to
manipulate the grip and moving it as close as possible to the center of the rocket. For help, you can
switch to grid drawing mode by pressing the [4] key.
Make sure that the flap is still selected and select Edit-> Duplicate Special □ from the menu. In the
second column of the Rotate row, enter the value 60 (the second column represents the rotation around
the y axis). Enter a value of 5 in the Number of Copies field and press the Apply button. As a result, we
get 5 new flaps in the appropriate places.
For the end, all we have to do is mark all the objects together, make a new rocket group and save the
scene by selecting from the File-> Save menu.
Output:

Page | 9
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Experiment 3
3. Application of texture to the spaceship?

Steps:
3.1 Starting the ship
This spaceship will be built starting with a simple polygonal cube .The Poly Faces will then be extruded
to create a more complex shape.
1 Place and position a primitive cube
Select Create->Polygon Primitives->Cube
2 Turn on backface culling
The Poly Faces that are facing away from the view are not displayed and cannot be selected
3 Select the two side faces of cube
Press the Shift key and Select the opposite facet handle
4 Extrude and scale Poly Faces
Select Polygons->Extrude
5 Add wing base
Press the g key to reactivate the Extrude tool and start a new extrusion
6 Extrude and shape wing
Press the g key. Click-drag on the blue Move handle. Click-drag on red Scale handle.
8 Add a top wing
Select the facet handle belonging to the top surface of the shape. Press the g key. Click-drag on red
Scale handle to create a long thin polygon centered in the top facet.
3.2 Air intake ports
In addition to extruding out, you can use the extrusion tool to push a polygonal facet into a surface to
create an opening. For the ship’s air intake ports, this technique will be used.
2 Create the front of the ports
Select the facet handle belonging to the side thruster port. Press the Shift key and Select the opposite
facet. Press the g key to re-evoke the Extrude tool and start a new extrusion.
2 Add a lip to the ports
To give the thruster a little bit of an edge, you will next create a little lip using the extrude tool.Press the
g key.
3 Extrude the hole
Press the g key.
Click-drag on blue Move handle to push this facet back deep into the spaceship
4 Add the rear thruster
Tumble the view around to see the back of the ship.Select the facet handle belonging to back facet of
the ship. Press the g key.
Repeat the steps used to create the front thruster ports to finish the back exhaust hole
3.3 The front cockpit
You can now continue to use the extrude tool to pull out a cockpit area for the spaceship.
1 Pick the front facet
Tumble around to see the front of the ship.
Select the facet handle belonging to front facet of the ship.
2 Extrude the front facet twice
Press the g key.
Click-drag on blue Move handle to pull this facet out.
Press the g key.
Page | 10
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Use blue Move handle to pull a second facet out.
3 Scale and rotate the facet
Use the green Scale handle to scale the front facet down.
Use the red Scale handle to scale this facet in.
Use the green Move handle to move this piece down
3.4 Creating a more organic look
1 Smooth the spaceship
Press F8 to go back to Select by Object Type mode
Select Edit Polygons -> Smooth.
2 Edit the extrude history
In the Channel box, Select the polyExtrudeFacet1 node.
Select the Show Manipulator Tool.The manipulator for the first extrusion is displayed.
Use the blue Move handle to move the extrude in towards the center.
Both the extrude history and smooth action update, as the exhaust ports become more narrow
3 Edit the smooth history
Select the polySmoothFacet1 input node in the Channel box.
Set Divisions to 2.
4 Add a lattice
Change to the Animation menu set.
Select Deform -> Create Lattice.
In the Channel box, set the following under the ffd1LatticeShape node:
S Divisions to 4;
T Divisions to 2;
U Divisions to 6.
5 Edit the lattice points
Press F8 to go into Select by Component Type mode
Turn on the Points selection mask.The Poly Faces selection mask should turned off.
In the Top view, use the Shift key and click-drag to Select the twelve control points near the tips of the
wings
6 Move the tail
In the Perspective view, Select the six control points closest to the tail.
7 Move the lower back edge down
In the Side view, Select the four control points at the back lower edge.
Move these points down.
8 Move the wings tips down
In the Front view, Select all the control points on the right and left sides of the lattice.
Move these points down
9 Curve the nose forward and down
In the Side view, Select the front two rows of control points.
Move these points forward and down.
3.5 Finishing the model
1 Delete history
Press F8 to go back to Select by Object Type mode.
Select the spaceship.
Select Edit ->Delete by Type ->History.
2 Rename the polymesh
Rename the polymesh polyShip.

Page | 11
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
3 Save the file
Select File -> Save Scene As...
Save the file as polyShip.
3.6 Texturing the Ship
1 Create and assign a new shading group
• Open the Hypershade window.
• Create a Blinn Material node.
• Assign the Blinn Material to the polymesh object.
• Rename the material node polyShipBlinn.
• Rename the blinn1SG node to polyShipSG.
2 Turn on hardware texturing
• Turn on hardware texturing in each view panel
The display of the model does not change because there are no textures assigned
3 Map an image file to the color
• Open the attributes for the polyShipBlinn node.
• Map the Color attribute with a 2D File texture node.
• Rename the file1 node polyColor.
• Click on the Folder Icon button next to Image Name.
• In the sourceimages directory of the projectTwo project, locate the polyColor.sgi image file.
• Click See Image.

Output:

Page | 12
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 4
4. Export a 3D model from maya (.fbx file)?
Steps:-
1. Launch Maya.
2. Select File > Export All, or File > Export Selection. The Export All, or Export Selection
dialog box appears.
3. Select FBX from File of Type menu
4. Enter a name for the FBX file you want to export.
5. The FBX Export options appear at the right of the Maya Export dialog box.
6. Set the export options you want to use or select a preset from the Presets menu
7. If file contains textures and maps, it is important to activate the Embed Media option
8. Click Export in the Maya Export dialog box
Output:

Page | 13
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 5
5. Export a model from Z-Brush to maya?
Steps:
If you need to bring a model from ZBrush back into Maya for further editing or
rendering, it is done as an .obj.
1. In ZBrush select Tool Export.
2. Open Maya and select File Import . Set Create Multiple objects to False. This
is very important. If the vertex order of the object changes in any way, the
models will not work correctly when moving between the two programs.
Output:

Page | 14
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 6
6. Create a sprite sheet and its animation in unity?
Steps:
1. Download assets (fire_fx_v1.0.zip) from https://brullov.itch.io/fire-animation
2. First start by creating a 2D project in Unity
3. To start things off, simply drag and drop your sprite sheet into the Assets
4. Now that we have a spritesheet to work with, we need to tell Unity that it’s a spritesheet, or in other
words, an image containing multiple images. To do this we have to perform a couple of steps. Select
the newly installed sprite, then in the Inspector, follow the following steps:
a. Select Sprite Mode
b. Select ‘Multiple’
c. Click ‘Sprite Editor Button’
5. When prompted to apply import settings, click Apply
6. Now in the Sprite editor, select Slice then Type then Grid by Cell Count
7. In this case sprite sheet is composed of 1 rows with 6 columns in each. So enter the appropriate values
in Columns & Rows, then click the Slice button.
8. Now apply the slice
9. Now expand the newly created sprite set by clicking the play icon to the right.
10. Once expanded, select the frames of animation you want to include in your animation. You can hold
Ctrl when clicking to select multiple frames of animation. Once selected, drag and drop in the view.
11. You will now be prompted to create an animation. I called FIRE_ANIMATION, then click Save.
12. click on play
Outputs:

Page | 15
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Experiment 7
7. Creation of basic transformation in unity using c script?
Steps:

1. First, create 2D Unity project.


2. Click on the "GameObject" menu in the menu bar. Select 3D objects and pick the "sphere"
option. The sphere will be added to the scene View.
3. Click on the Play button. The sphere will now appear in-game View
4. Create a C# Script by Right-click on Assets. Select Create >> C# script.
5. Rename the script as a move
6. Double click on the move script. The MonoDevelop-Unity editor will open up.
Move the object forward

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (0.05f, 0f, 0f);
15.
16. }
17. }

7. Go back to the Unity window. Drag and drop the move script onto the sphere.
8. Click on the Play button. The sphere will move slowly in a forward direction.
Object moves backward

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
Page | 16
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (-0.05f, 0f, 0f);
15.
16. }
17. }

9. Save the program. The sphere will move in a backward direction.


Up

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (0.05f, 0.05f, 0f);
15.
16. }
17. }

10. Save the program. Go to Unity and click on the Play button. The sphere will move upward
Down

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {

Page | 17
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (0.05f, -0.05f, 0f);
15.
16. }
17. }

11. Save the program.


Left

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (0.00f, 0.00f, 0.05f);
15.
16. }
17. }

12. Save the program


Object move up, forward and left

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.

Page | 18
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
12. // Update is called once per frame
13. void Update () {
14. transform.Translate (0.001f, 0.01f, 0.01f);
15.
16. }
17. }

13. Save the program. Go to Unity and click on the Play button. The sphere will be moving slowly
to the right.
Move the object by keypress

1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4.
5. public class move : MonoBehaviour {
6.
7. // Use this for initialization
8. void Start () {
9.
10. }
11.
12. // Update is called once per frame
13. void Update () {
14. if (Input.GetKey (KeyCode.W)) {
15. transform.Translate (0.05f, 0f, 0f);
16. }
17. if (Input.GetKey (KeyCode.S)) {
18. transform.Translate (-0.05f, 0f, 0f);
19. }
20. if (Input.GetKey (KeyCode.D)) {
21. transform.Translate (0.0f, 0f, -0.05f);
22. }
23. if (Input.GetKey (KeyCode.A)) {
24. transform.Translate (0.0f, 0f, 0.05f);
25. }
26. }
27.
28. }

14. Save the program.


15. Go to the Unity window. Click on the Play button. Press the “W” key. The object will be
moved to the front.
16. Press the “S” key. The object will be moving back

Page | 19
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
17. Press the “D” key. The object will move into the Right side.
18. Press the “A” key. The object will move into the left side
Output:

Page | 20
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 8
8. Building health bar and control values on it with c script?
Steps:
1. Create a new project.
2. In new scene, create an empty game object and call it Player.
3. Once created, select the Player game object and navigate to the Inspector window and reset the
transform component
4. Next, click on the Add component button and look for Sprite Renderer using the search bar.
5. Once Sprite Renderer is added, navigate to it and click on the little circle beside the Sprite
parameter. Then, look for Knob and select it
Adding Health Points:
6. Of course, before we can create the health bar we will need first to create the health points.
7. To start, we’re gonna need to create a new C# script and we’ll call it Health.cs.
1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4. public class Health : MonoBehaviour
5. {
6. public int curHealth = 0;
7. public int maxHealth = 100;
8. public HealthBar healthBar;
9. void Start()
10. {
11. curHealth = maxHealth;
12. }
13. void Update()
14. {
15. if( Input.GetKeyDown( KeyCode.Space ) )
16. {
17. DamagePlayer(10);
18. }

Page | 21
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
19. }
20. public void DamagePlayer( int damage )
21. {
22. curHealth -= damage;
23. healthBar.SetHealth( curHealth );
24. }
25. }
8. what we’re doing is we’re creating a set of functions that initialize the value of the current health
of the player to the maximum. Then, we also have the function that gives damages to the player.
So, if you take a look at the Update function, as you can see we’re checking if the Player hits the
SPACE bar, if the player did, then the player will receive damage.
Creating the Health Bar:
9. Now that we have our player health points set up, let’s begin working on displaying the actual
health bar.
10. To start, navigate to your hierarchy, right-click and select UI then Image.
11. This will be creating a new canvas especially if there’s currently none in the scene. Inside the
canvas, there will also be an image UI object created.
12. With all that being said, select your Canvas game object and press F key to show the entire
canvas on the screen.
13. Next, select your Image game object and make sure that it is placed right at the center of the
canvas like below.
14. Next, we’ll be changing the graphic being used in this object so download the PNG image
provided below and import it to your project.
15. To import the downloaded file, just navigate to the file that you wish to import and then just
simply drag it into your project window like below.
16. Another way to import your files is by going to your assets folder which is located in your project
folder.
17. Once the image is imported, go back to your hierarchy, select the Image UI object and navigate
to its Image component and change its Source Image to the image that we have just imported.
The health bar.
18. Next, just below the Preserve Aspect check box, click the Set Native Size button.
19. This will resize the image based on the actual resolution of the image file.
20. Next, let’s rename our Image UI object to something like… Health Bar Border.
21. The next thing that we’re going to do is to create an empty game object inside the Canvas. So
right-click on the Canvas game object and select Create Empty
22. Let’s rename this Empty game object to Health Bar
Page | 22
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
23. Next, with the Health Bar game object selected press T. This will enable the Rect Tool.
24. Now, resize the Health Bar to the same size as the Health Bar Border.
25. Next, drag the Health Bar Border game object to the Health Bar game object to make it as its
child, like below.
26. Let’s create another Image, so with your Health Bar game object selected, right-click then
navigate to UI then select Image.
27. simply drag the Image object above the Health Bar Border game object like below
28. Now let’s change the color of this image since this object will represent the actual bar for the
player’s health point.
29. But before that, let’s rename first our Image game object to Health Bar Image because we don’t
want it to call as Image all the time.
30. Nice! Now let’s select our Health Bar Image and navigate to its Image component.
31. In the color property, change its hexadecimal value from #FFFFFF to #DB2525.
32. Now, we want our Health Bar Image to be the same size as its parent so to do that, go to its Rect
Transform component and click on the box with the red cross in it. This will show you the anchor
presets
33. With the anchor presets being showed, hold ALT key, and select the stretch preset at the bottom-
right corner of the preset’s window.
34. This will fill the entire Health Bar game object.
35. Select the Health Bar Border game object and navigate to its Rect Transform component and
click on the Anchor Preset button and select the preset at the bottom-right corner. Without
pressing the ALT key.
Using Slider UI for the Health Points:
36. Now the next thing that we’re going to do is to make the Health Bar an actual health bar where
the red fill can decrease or increase.
37. To do that, we’re going to use the Slider component.
38. So with your Health Bar selected, go to its inspector and click Add Component and look for
Slider
39. Next, we’re going to set the Slider component to the following values.
a. Interactable is unchecked
b. Transition is set to none
c. Navigation is set to none
d. Fill Rect, drag the Health Bar Image object to its value
40. By doing so, a new set of parameters will show up such as the direction of the slider, the
minimum and the maximum value, and the actual value.
41. By sliding the value you will see that the Health Bar Image also gets affected.
Page | 23
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Scripting the Health Bar:
42. So with your Health Bar game object selected, click the Add Component and look for New
Script. Select that and set the name of the script to HealthBar.
43. Once the script is created, open it with visual studio and copy the following code.
1. using System.Collections;
2. using System.Collections.Generic;
3. using UnityEngine;
4. using UnityEngine.UI;
5. public class HealthBar : MonoBehaviour
6. {
7. public Slider healthBar;
8. public Health playerHealth;
9. private void Start()
10. {
11. playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent<Health>();
12. healthBar = GetComponent<Slider>();
13. healthBar.maxValue = playerHealth.maxHealth;
14. healthBar.value = playerHealth.maxHealth;
15. }
16. public void SetHealth(int hp)
17. {
18. healthBar.value = hp;
19. }
20. }
Using the Script:
44. Once all your scripts are saved, navigate back to your hierarchy and select your Player game
object.
45. Then, drag the Health.cs script to its inspector to assign the script.
46. Go to its inspector and drag the Health Bar game object to the Health Bar parameter of the health
script like below.
47. Still with your Player selected, navigate to the Tag dropdown and select Player.
48. Save your scene and test your game.
49. Your player’s health should decrease whenever you hit your spacebar.
Page | 24
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Output:

Page | 25
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 9
9. Experiment with canvas object- creation of text box, buttons and control them with
c script?
Steps:
1. Create new project in unity
2. To add text to your game, Go to GameObject->UI->Text-TextMeshPro
3. To change things at run time,need to write code to update the text while we are playing
TextUpdater Script.cs:
This script updates text value to match the number of seconds our game has been playing
using TMPro;
using UnityEngine;

public class TextUpdater : MonoBehaviour


{
public TMP_Text TimeText;

void OnEnable(){

TimeText.SetText(Time.time.ToString());
}
}
4. Lets add a button to refresh that time whenever it’s clicked
Add a Button:
5. Goto GameObject ->UI->Button-TextMeshPro
6. Set Height and width to 300
7. Expand the button and select the Text TextMeshPro and make it Refresh
8. Button is clickable but it wont actually do anything
9. Scroll down to Button component,expand it,see an OnClick() Section,hit the +
button,drag the player text object here and click on the function objects .This shows all of
the components on that object including TextUpdater and all of the public methods on

Page | 26
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
there now on enable method isn’t public
10. We don’t call an enable method from button,instead refactor the above code by moving
the time text code into a public method named RefreshTimeText as shown below:
using TMPro;
using UnityEngine;

public class TextUpdater : MonoBehaviour


{
public TMP_Text TimeText;

void OnEnable()=>RefreshTimeText();
public void RefreshTimeText(){

TimeText.SetText(Time.time.ToString());
}
}

11. calling RefreshTimeText on enable and add that as an onclick listener so choose
dropdown choose TextUpdater and can find RefreshTimeText
12. Press Play

Output:

Page | 27
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Experiment 10
10. Experiment with onCollisionEnter2D() and onCollisionExit2D() methods in
unity?
Steps:

1. Create 3D Object QUAD


2. Remove Mesh Collider Component in Inspector tab of QUAD
3. Add Component Box Collider 2D Component to QUAD
4. Add Rigid body 2D Component to QUAD
5. If run Play,QUAD just falls due to gravity
6. Right click on QUAD and duplicate it.Move this down ,scale it.
7. Since we duplicated,it already has a Box Collider 2D and rigidbody 2D attached
8. If run Play now,both of the quads goes down
9. We don’t want duplicated quad to fall down,first quad stay still and fall down on duplicated
quad and when both of them collides,one of them to destroy
10. Select Kinematic as Body type in Rigidbody 2D component of Second Quad so that it will not
be affected by external forces
11. Run Play now and can see that First Quad moves and stays on the Second Quad
12. Add aTag to the First Quad names quad
13. Add a Tag to Second Quad by creating a tag named “raja”
14. Now,Add the Test script to the above quad by Add component ->scripts
15. Inside the script,we can write code to detect collisions
16. Special Function called OnCollisionEnter2D and inside the function as a parameter we have to
pass Collision 2D and name the variable “col”.This function gets called whenever it is collided
with any other GameObject.Inside this function,write Debug.Log(“Collision”)
17. Again Check,if it has a tag “raja”,then we are going to destroy this object.
18. Inside the CollisionEnter2D function,if it has a tag “raja”,then we are going to destroy that
object by Destroy(col.gameObject).
19. Run play, the first quad fall it on Second Quad and Second Quad get destroyed
20. Suppose , simply call Destroy(gameObject) destroy First Quad instead of Second Quad
1. using System.Collections;

2. using System.Collections.Generic;
Page | 28
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
3. using UnityEngine;
4.

5. public class Test : MonoBehaviour

6. {

7. // Start is called before the first frame update


8. void Start()

9. {

10.

11. }

12.

13. // Update is called once per frame

14. void Update()


15. {

16.

17. }

18. void OnCollisionEnter2D(Collision2D col){


19. Debug.Log("Collision");

20. Destroy(col.gameObject);

21. }

22. void OnCollisionStay2D(Collision2D col){

23. Debug.Log("Collision stay");

24.

25. }

26. void OnCollisionExit2D(Collision2D col){

27. Debug.Log("Collision exit");

28. }

29.

30. }

Page | 29
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Output:

Page | 30
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
Experiment 11
11. Controlling transitions in animator based on boolean and float variables?

Steps:

1. Download X [email protected], X [email protected], X Bot@Standard Idle.FBX,


character.FBX by signing into https://www.mixamo.com/.
2. Imports X [email protected], X [email protected], X Bot@Standard Idle.FBX,
character.FBX into Unity2D project assets.
3. First, drag and drop character.FBX files into hierarchy.
4. Expand X [email protected], X [email protected], X Bot@Standard Idle.FBX in assets
and select respective animation file and press ctrl+D to separate animations from FBX files
Animator Setup:
5. Create an Animator Controller: Navigate to `Assets > Create > Animator Controller`. Name
it something like `CharacterAnimator`.
6. Attach Controller to Character: Attach this Animator Controller to the Animator component
of your character.
7. Add Animation States: Double-click your Animator Controller to open it. Right-click within
the Animator window to create three new states: `Idle`, `Walk`, and `Run`
8. Link Animations: Drag your Idle, Walk, and Run animations onto their corresponding states.
Parameters and Transitions:
9. Add Float Parameter: In the Animator window, click `Parameters` and add a new float called
`Speed`.
10. Add bool Paramters: In the Animator window, click `Parameters` and add new bool
variables idle, walk, run.
11. Set Transitions: Create transitions between `Idle <-> Walk`,`Walk <-> Run` and ‘Idle<-
>Run’
12. Add Condition: Click on the transition arrow idle->walk, go to the Inspector, and add a
condition ‘walk=true’ using the idle parameter to control the switch
13. Add Condition: Click on the transition arrow walk->run, go to the Inspector, and add a
condition ‘run=true’ using the idle parameter to control the switch
14. Add Condition: Click on the transition arrow run->idle, go to the Inspector, and add a
condition ‘idle=true’ using the idle parameter to control the switch
15. Add Condition: Click on the transition arrow run->walk, go to the Inspector, and add a
condition ‘walk=true’ using the idle parameter to control the switch
16. Add Condition: Click on the transition arrow walk->idle, go to the Inspector, and add a
condition ‘idle=true’ using the idle parameter to control the switch

Page | 31
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)
17. Add Condition: Click on the transition arrow idle->run, go to the Inspector, and add a
condition ‘run=true’ using the idle parameter to control the switch
18. Select character in Hierarchy and click on add component ,create new script with the
following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
Animator animator;
// Start is called before the first frame update
void Start()
{
animator=GetComponent<Animator>();

animator.SetBool("idle", true);
animator.SetBool("walk", false);
animator.SetBool("run", false);
animator.SetFloat("speed",1.0f);

// Update is called once per frame


void Update()
{
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
animator.SetBool("run", true);
animator.SetFloat("speed",3.0f);
return;
}

Page | 32
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

else if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) ||


Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
{
animator.SetBool("walk", true);
animator.SetFloat("speed",1.0f);

return;
}
else {
animator.SetBool("run", false);
animator.SetBool("walk", false);
animator.SetBool("idle", true);
animator.SetFloat("speed", 0.0f);
}
}
}
Outputs:

Page | 33
Lab Record Computer Animation & Game Design Lab
(20CSLJO03)

Page | 34
Experiment 12
12. Implement camera following in unity with c script?
Steps:
1. Create Unity Project and select layout as 2 by 3.
2. Import Soccer ball from asset store in Unity
3. Select Soccer ball and click on Add Component in Inspection tab and select new script and
rename it as move and add the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class move: MonoBehaviour


{
// Start is called before the first frame update
void Start()
{

// Update is called once per frame


void Update()
{
if (Input.GetKey (KeyCode.W)) {
transform.Translate (0.05f, 0f, 0f);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (-0.05f, 0f, 0f);
}
if (Input.GetKey (KeyCode.D)) {

Page | 35
transform.Translate (0.0f, 0f, -0.05f);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (0.0f, 0f, 0.05f);
}
}
}
4. Select Main Camera,click on Add Component in Inspection tab and create new script and rename
it as CameraFollow.cs and select target as Soccer ball.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour


{
public Transform target;
Vector3 offset;

// Start is called before the first frame update


void Start()
{
offset=target.position-transform.position;
}

// Update is called once per frame


void Update()
{

Page | 36
private void FixedUpdate(){
transform.position=target.position-offset;
}
}
5. Run Play , Select Game tab and move the Soccer ball by pressing W,A,S,D Keys ,observe that
camera also moves along with the Soccer ball in Scene

Output:

Page | 37
Experiment 13
13. Creation of animated materials in unity?
Steps:

1. Create Unity 3D Project

2. Create 3D Object ->Cube in Hierarchy tab

3. In the Project Window,Right Click and Create Material and Check the Emission in
Inspector tab and Select a color
4. Add Animation tab in Project tab by right clicking and selecting Animation in add tab

5. Select the Cube and Click on Create in the Animation tab and save as New Animation in
Assets->Scene Folder.
6. Add the property to the animation by selecting Mesh Render->Material.Emission.color

7. Select the time frame as 0.30 in curves tab

8. click on AddKeyFrame ,press on Record Button to start ,select new color from the New
Material Emission color and again press on Record Button to stop
9. Repeat Step8 for time frames 1:00,1:30,2:00,2:30 and 3:00

10. Run play and observe the animated cube projecting different colors
Output:
Experiment 14
14. Import 3D model into unity from maya?
Steps:
1. Open Maya 2024
2. Choose one of the Scenes(selecting Spaceship)
3. Select the Object
4. File->Export Selection->Select File types as FBX Export->click on Export Selection-
>Give file Name and save
5. Create New 3D Project in Unity
6. Right Click in Assets and Select Import New Assets
7. Give the path of the file saved in Step4
8. Drag the spaceship from assets to Hierarchy or Game tab
9. Click on Spaceship in Hierarchy tab
Output:
Experiment 15
15. Creation of 3D game in unity with multiple states?
Steps:
1. Download survival shooter game zip file from
https://github.com/EvanderChristianDumalang/Survival-Shooter

2. Extract the zip file


3. Create 3D Unity Project
4. Drag the Folder extracted onto Assets
5. Go to Assets->Scenes->level 01.unity and drag level 01.unity onto the Hierarchy tab
6. Run Play

Output:

You might also like