void OnCollisionStay2D(Collision2D other) { if (other.gameObject.CompareTag("FishSchool")) { currentFishSchool = other.gameObject.GetComponent <FishSchoolGameScript>(); } }
void Start() { controls = GetComponent <MouseControls>(); fishMeterNeedle = FindObjectOfType <FishMeterNeedle>(); audioPlayer = FindObjectOfType <AudioPlayer>(); mainGameScript = FindObjectOfType <MainGameScript>(); fishStack = GetComponentInChildren <FishStack>(); currentFishSchool = null; currentWeight = 0.0f; newDay = false; }
void OnCollisionExit2D(Collision2D other) { if (other.gameObject.CompareTag("FishSchool")) { if (currentFishSchool != null) { if (other.gameObject == currentFishSchool.gameObject) { currentFishSchool = null; } } } else if (other.gameObject.CompareTag("Dock")) { isDocked = false; } }
IEnumerator StartFishing() { isFishing = true; yield return(new WaitUntil(() => controls.GetMouseButtonDown(0))); if (currentFishSchool != null) { if (Mathf.Abs(fishMeterNeedle.GetNormalizedValue()) <= fishingMeterTolerance) { currentWeight += currentFishSchool.weight; Debug.Log($"Successfully fished a {currentFishSchool.weight:F2}kg. fish!"); audioPlayer.PlaySound(audioPlayer.fished); } else { Debug.Log($"Failed to fished a {currentFishSchool.weight:F2}kg. fish"); } } isFishing = false; lastFishedSchool = currentFishSchool; yield return(null); }