#Producer #Programmer
This game was created with the help of two other people :) It was fun to create something as a team and see it all come together. I worked on the hooking mechanics of the game, some UI stuff, the sound, and the inspectors of the fish.
Some extra things I did
I personally worked on polishing and working out some of the core mechanics of the game over winter break. I added the score on the end screen, polished the hooking mechanic, added more sounds, and put in the pop-up instruction text at the start of the game.
In the future, we would like to incorporate more sound effects, and a luck of chance if the fish hooks onto your line instead of just always catching on collision. Also adding an instructions button on the starting menu.
Some of my code
The hook works when it collides with the mouth of the fish, then it will latch on. You can bring your mouse up and once it is at catching height, then you are able to press space to catch. Each fish sprite is tagged so depending on what type of fish it is, is how many points you've earned. Some of the hardest parts to code exactly how I wanted it was when the fish hooks, it stops moving and positions itself right on the hook. The other was figuring out the catching height. When building this project for web, all calculations originally were extremely off. I found that Unity has a setting to size with whatever screen.
However, I thought about also having the mechanic be once it collides with the boat, then IsAtCatchingHeight = true
. Besides the hook class, I had two others for drawing the fishing line and one for the movement of the hook.
What I would do differently now is to create an observer class for the hook since a lot of the logic is if statements and booleans.
using System;
using UnityEngine;
public class Hook : MonoBehaviour
{
public UI UI;
public FishBehavior FishBehavior;
private Fish fish;
private HookMovement hookMovement;
private bool hasFishOnHook = false;
public void Update()
{
if (hasFishOnHook)
{
if (hookMovement.IsAtCatchingHeight())
{
TryToCatchFish();
}
}
}
public void OnTriggerEnter(Collider other)
{
if (hasFishOnHook)
return;
if (other.gameObject.CompareTag("Fish") ||
other.gameObject.CompareTag("MediumFish") ||
other.gameObject.CompareTag("HardFish"))
{
hookMovement = GetComponent<HookMovement>();
if (FishBehavior.HookProbability() == true)
{
fish = other.gameObject.GetComponent<Fish>();
PutFishOnHook(other.gameObject.GetComponent<SpriteRenderer>(),
gameObject.GetComponent<SpriteRenderer>(),
fish.SpriteOnLeftSide);
fish.StopMoving();
}
else
{
return;
}
}
}
public void PutFishOnHook(SpriteRenderer one, SpriteRenderer two, bool isOnLeft)
{
hasFishOnHook = true;
Vector3 centerPosition = two.bounds.center;
one.transform.position = centerPosition;
if (fish.SpriteOnLeftSide)
one.transform.Rotate(Vector3.forward, 90f);
else
one.transform.Rotate(Vector3.forward, -90f);
one.transform.SetParent(two.transform);
}
private void TryToCatchFish()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (fish.gameObject.CompareTag("MediumFish"))
{
ScoreKeeper.Add(20);
} else if (fish.gameObject.CompareTag("HardFish"))
{
ScoreKeeper.Add(40);
}
else
{
ScoreKeeper.Add(10);
}
Destroy(fish.gameObject);
UI.ShowScore(ScoreKeeper.Get());
EmptyHook();
}
}
private void EmptyHook()
{
hasFishOnHook = false;
}
}