- Create ground and idle image using gimp
- Learn about layers
- Learn about image sizing
- Learn about selection tool
- Learn about exporting image
- Setup Unity Project
- Learn about navigating the basic environment
- Get familiar with unity environment
- Create idle player animation in gimp
- Learn about frames and creating different images
- Learn to preview the animation in using playback
- Add
replace
to the layer
- Add
- Learn to export the layers as a sprite strip using
Fuse Layers
- Implement idle player animation in unity
- Familiarize with the scripting system in unity
- Create a C# script name
PlayerController
- C# is a object oriented language
- Is a programming language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.
- This script will be responsible for moving the player around.
- Importing packages at the top of the page
- It's giving our program access to those packages or code someone else has written for us.
- What is a class?
- Think of it as an extensible template
- Provides initial values for state (member variables)
- Contains implementations of behaviors (member functions)
- What is a member variable ?
- Add
float maxSpeed = 20f;
- A variable is a storage location
- Describe putting something into a cup
- It has a type, meaning that only certain kinds of values can be stored into it. Some basic ones are:
- Number, in our case a floating point number
- String or text, a word or words in a paragraph
- Boolean or true/false
- We assign is a default value of 10
- Add
bool facingRight = true;
- Add
- What is a member function?
- Change
Update
toFixedUpdate
- A function is a subroutine or a sequence of program instructions that perform a specific task.
FixedUpdate
is a function that the unity engine will call for every frame rendered on a fixed time line
- Change
- Lets move the character
void FixedUpdate { float move = Input.GetAxis("Horizontal"); rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y); }
- Create
run
state animation- Add parameter named
speed
in the animator control - Make a transition from
idle
torun
when speed is > .01 - Make another transition from
run
toidle
when speed is < .01
- Add parameter named
- Create a new function to flip
void Flip() {
facingRight = !facingRight;
Vector3 scale = transform.localScale;
scale.x = scale.x * -1;
transform.localScale = scale;
}
- What is an conditional statement?
- Add flip to the update calls
if (move > 0 &&!facingRight) {
Flip();
} else if (move < 0 && facingRight) {
Flip();
}
void Update() {
if (grounded && Input.GetKeyDown(KeyCode.Space)) {
anim.SetBool("Ground", false);
ridigbody2D.AddForce(new Vector2(0, jumpForce);
}
}
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
... in Fixed updated
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool("Ground", grounded);
- Create Empty object, call it GroundCheck
- Nest it under the character
- Pick an icon so we can see it
- click and drag to where the ground should be under the character
- drag and drop ground check object ont Controler script
- put player on the player layer
- Select whatIsGround to be everything except play
- Create animator param name Grounded
- Create CameraController script and link to camera
public Transform player;
public Vector3 offset;
void Update () {
transform.position = new Vector3 (player.position.x + offset.x, player.position.y + offset.y, offset.z);
}
-
set offset to 3,3,-20
-
set size to 20
-
to reset the game we need to reload it
void Update() {
if (Input.GetKeyDown(KeyCode.Return)) {
Application.LoadLevel(0);
}
}