public void leaveFishingArea(FishType fishType) { currentFishAreas.Remove(fishType); if (currentFishAreas.Count == 0 && rod != rodState.Idle) { //animate + play sound of fish escaping. xAnimator.Play("appear"); audio.PlayOneShot(escape_sound); rod = rodState.Idle; } }
// Update is called once per frame void Update() { nextFishTimer -= Time.deltaTime; hungerTimer -= Time.deltaTime; //consume fish if (hungerTimer <= 0) { GameManager.Instance.decFishingHealth(fishHealthDecrease); StartCountdown(fishConsumeTime, fishConsumeTime + 2f, true); } if (currentFishAreas.Count != 0) { switch (rod) { case rodState.Idle: if (nextFishTimer <= 0) { StartCountdown(minPokeTime, maxPokeTime); SetPokes(); Poke(); rod = rodState.Waiting; } if (Input.GetKeyDown(KeyCode.Alpha1)) { StartCountdown(minIdleTime, maxIdleTime); rodAnimator.Play("pull"); rod = rodState.Idle; } break; case rodState.Waiting: if (nextFishTimer <= 0) { Poke(); StartCountdown(minPokeTime, maxPokeTime); } if ((pokeCount) == 0) { rodAnimator.Play("hold"); audio.PlayOneShot(splash_sound); // Debug.Log("hold"); rod = rodState.Catch; break; } if (Input.GetKeyDown(KeyCode.Alpha1)) { rodAnimator.Play("pull"); // Debug.Log("escape"); audio.PlayOneShot(escape_sound); StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; xAnimator.Play("appear"); break; } break; case rodState.Catch: if (nextFishTimer <= 0) { rodAnimator.Play("pull"); // Debug.Log("escape"); xAnimator.Play("appear"); audio.PlayOneShot(escape_sound); StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; break; } if (Input.GetKeyDown(KeyCode.Alpha1)) { //rodAnimator.Play("catch"); rodAnimator.Play("pull"); // Debug.Log("catch"); audio.PlayOneShot(catch_sound); fishCount += 1; GameManager.Instance.HealthUpdate(GameManager.HealthType.Fishing); Collider[] colliders = Physics.OverlapSphere(raftTransform.position, radius); FishType closest = FishType.None; float minDistance = 200; foreach (Collider hit in colliders) { GameObject go = hit.gameObject; if (go.CompareTag("FishingArea")) { float distance = (go.transform.position - raftTransform.position).magnitude; if (distance < minDistance) { minDistance = distance; } closest = go.GetComponent <FishingArea>().getFishType(); //Debug.Log("closest fishing area check, checking area with index " + go.GetComponent<FishingArea>().getFishType()); } } SpawnFish((int)closest); fishHit((int)closest); //Debug.Log("caught fish with type index: " + (int)closest); StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; break; } break; } } else { StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; hungerTimer -= Time.deltaTime; if (hungerTimer <= 0) { consumeFish(); StartCountdown(fishConsumeTime, fishConsumeTime + 2f, true); } switch (rod) { case rodState.Idle: if (timer <= 0) { StartCountdown(minPokeTime, maxPokeTime); SetPokes(); Poke(); rod = rodState.Waiting; } if (Input.GetKeyDown(KeyCode.Alpha1)) { StartCountdown(minIdleTime, maxIdleTime); rodAnimator.Play("pull"); rod = rodState.Idle; } break; case rodState.Waiting: if (timer <= 0) { Poke(); StartCountdown(minPokeTime, maxPokeTime); } if ((pokeCount) == 0) { rodAnimator.Play("hold"); // Debug.Log("hold"); rod = rodState.Catch; break; } if (Input.GetKeyDown(KeyCode.Alpha1)) { rodAnimator.Play("pull"); // Debug.Log("escape"); audio.PlayOneShot(escape_sound); StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; xAnimator.Play("appear"); break; } break; case rodState.Catch: if (timer <= 0) { rodAnimator.Play("pull"); // Debug.Log("escape"); xAnimator.Play("appear"); audio.PlayOneShot(escape_sound); StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; break; } if (Input.GetKeyDown(KeyCode.Alpha1)) { //rodAnimator.Play("catch"); rodAnimator.Play("pull"); // Debug.Log("catch"); audio.PlayOneShot(catch_sound); fishCount += 1; StartCountdown(minIdleTime, maxIdleTime); rod = rodState.Idle; int fishType = SpawnFish(); FishingManager.SharedInstance.fishHit(fishType); Debug.Log("caught fish with type index:"); Debug.Log(fishType); break; } break; } }