Brawler

My first Unity game was a simple stage fighter, where I designed all the pixel art myself. It featured basic mechanics, and allowed me to experiment with core game development concepts like animation, collision detection, and physics. Creating the pixel art added a personal touch and gave me full control over the visual style. This project helped me realize the amount of work that goes into games

My Code

Attack Feature

This script detects any hit colliders and adds a set amount of force

Attack Script


Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, DamageCollisions);
animat.SetTrigger("Attack1");
foreach(Collider2D enemy in hitEnemies)
{
    Debug.Log("Succesful hit");
    if (attackPoint == upAttack)
    {
        hpScript.knockbackPowerUp = 10;
        hpScript.knockbackPower = 1;
    } else if (attackPoint == downAttack)
    {
        hpScript.knockbackPowerUp = -2;
        hpScript.knockbackPower = 2;
    } else if (attackPoint == frontAttack)
    {
        hpScript.knockbackPowerUp = 5;
        hpScript.knockbackPower = 8;
    }

    hpScript.TakeDamage(attackDamage);
}
          

I check for any collisions in and store the detected colliders, i then proceed to add the knockback effect to the parent of the collider

Move Script

This script detects key input and adjusts movement and attacking direction.

Move Script


if (Input.GetKey(KeyCode.S))
{
    attackPoint = downAttack;


} else if (Input.GetKey(KeyCode.W))
{
    attackPoint = upAttack;

} else {attackPoint = frontAttack;}

hand.transform.position = attackPoint.position; //draws hand at current attack position

if (Input.GetKey(KeyCode.H) && attackStat == true)
{
    attackStat = false;
    attack();
}

if (attackStat == false)
{
    attackCounter += Time.deltaTime;
    if(attackCounter>attackCooldown)
    {
        attackCounter = 0;
        attackStat = true;
    } 
}
if (Input.GetKeyDown(KeyCode.D))
{
    moveInput = 1;
    FacingRight = true;
    animat.SetBool("Still", false);
}
else if (Input.GetKeyDown(KeyCode.A))
{
    moveInput = -1;
    FacingRight = false;
    animat.SetBool("Still", false);
}

if (Input.GetKey(KeyCode.D) == false && Input.GetKey(KeyCode.A) == false)
{
    moveInput = 0;
    animat.SetBool("Still", true);
}

//calculate the direction we want to move in and our desired velocity
float targetSpeed = moveInput * moveSpeed;
//calculate difference between current velocity and desired velocity
float speedDif = targetSpeed - rb.velocity.x;
//Calculate if our moveInput is 0 it will de accelerate, anything higher than 00.1 will make us accelerate
float accelRate = (Mathf.Abs(targetSpeed) > 0.01f) ? rbacceleration : rbdecceleration;
float movement = Mathf.Pow(Mathf.Abs(speedDif) * accelRate, velPower) * Mathf.Sign(speedDif);
rb.AddForce(movement * Vector2.right);
animat.SetFloat("Speed", Mathf.Abs(movement));
          

I check every frame for a key input and udate the moveInput to the respective direction

Suggested Projects

Vertical Slice

A group school project to remake a proffesional game

C# Icon Visual Studio Icon Unity Icon Blender Icon
Project Image

Fortress Defense

A school project to create a tower defense game

C# Icon Visual Studio Icon Unity Icon
Project Image