Book Report Day 3
Book Report 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:-
3
Edit the scale of Box Collider 2D to fit it to the png
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.
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:-
8
Now you can play your game . Good starting. Keep learning
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
9
{
// To access the Rigidbody and Animator component
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
spr = GetComponent<SpriteRenderer>();
}
if(hh<0)
{
spr.flipX = true;
}
else if (hh>0)
{
spr.flipX = false;
}
10