0% found this document useful (0 votes)
19 views11 pages

Book Report Day 3

The document outlines the steps for developing a mobile game character, including importing sprite sheets, creating animations, and adding physics components like Box Collider 2D and Rigidbody 2D. It also provides programming instructions for character movement using C#, detailing how to access components and handle user input. Finally, a sample code for 2D character movement is included to demonstrate the implementation of these concepts.

Uploaded by

navdeepsindhu
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)
19 views11 pages

Book Report Day 3

The document outlines the steps for developing a mobile game character, including importing sprite sheets, creating animations, and adding physics components like Box Collider 2D and Rigidbody 2D. It also provides programming instructions for character movement using C#, detailing how to access components and handle user input. Finally, a sample code for 2D character movement is included to demonstrate the implementation of these concepts.

Uploaded by

navdeepsindhu
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/ 11

Day 3

Mobile Game
Development

Navdeep
09th Aug, 2024
Import character sprite sheets into scene→

1
Create animation for character (idle):-

Select all 6 png sequence and drag and drop to scene window. It will ask for save option, give
any name.

2
Collider component:-

It is add component—>box collider 2D→enter

1. Select object (png)


2. Add component
3. Box Collider

3
Edit the scale of Box Collider 2D to fit it to the png

Now we need to add physics to the character. Ie Rigidbody 2D


1.select object
2.add component
3. Rigidbody 2D

4
We need to add Rigidbody 2D and Box Collider 2D component also to make character should no
go through the base of game play. Both object should have colliders.

Check the game now:-


1. Play
2. Object will fall down and collide with base
3. Collision it there between object 2 and object 3 as shown in picture

Programming is required to move the character inside game level:-


Create C# prog. By right click inside assets folder→ create→C#
Apply it to the Main character by drag and drop it to the inspector window.

5
First prog. Will look like this :-

6
Create variable : Variable is required to store some value. It can store one value and multiple
value also
float speed=10 single value
new vector2(x,y) two values
new vector3(x,y,z) three values

To access the component we need to assign it to variable name of that component. Eg. In start
function we are passing Rigidbody component to rb, ie, WE ARE ACCESSING RIGIDBODY
COMPONENT.
Start function will execute only once, at the starting of the game. Update function will execute
once per frame.
Movement of game object
Two ways to move a Game object with programming:-
1. Transform.position = old transform value + extra values (x,y,z) no rigid body
2. Name.velocity (x,y,z) If it is rigid body

7
How to access any Component with Programming:-

Taking user input ➖

8
Now you can play your game . Good starting. Keep learning

Code for 2D character movement:-

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

public class NewBehaviourScript : MonoBehaviour


{
// create a variable
public float speed = 2f;
public Rigidbody2D rb;
public Animator anim;
public SpriteRenderer spr;

// Start is called before the first frame update


void Start()

9
{
// To access the Rigidbody and Animator component
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
spr = GetComponent<SpriteRenderer>();
}

// Update is called once per frame


void Update()
{
//To take input from the user/ when they apply "A" or "D"
float hh = Input.GetAxisRaw("Horizontal");
//To move the character

if(hh<0)
{
spr.flipX = true;
}
else if (hh>0)
{
spr.flipX = false;
}

rb.velocity = new Vector3(hh, rb.velocity.y, 0);


}
}

10

You might also like