FishingController.cs finished
This commit is contained in:
parent
9e91220be4
commit
cf8851745d
3 changed files with 271 additions and 26 deletions
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Net.Mail;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
|
|
@ -20,62 +22,92 @@ public class FishingController : MonoBehaviour {
|
|||
|
||||
#endregion
|
||||
|
||||
public GameObject _exMark;
|
||||
|
||||
private double _fishingTime;
|
||||
private double _fishCooldown;
|
||||
private readonly float _minFishCooldown = 1.5f;
|
||||
private readonly float _maxFishCooldown = 7f;
|
||||
private readonly double _maxTime = 2f;
|
||||
private bool _fishing;
|
||||
private bool _catchable;
|
||||
private bool _caught;
|
||||
private double _fishCooldown;
|
||||
private readonly double _totalFishCooldown = 1.5f;
|
||||
private readonly double _maxTime = 2f;
|
||||
private bool _spawnFish;
|
||||
private Vector2 _ampsXY;
|
||||
|
||||
public bool Fishing => _fishing;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
ResetFishing();
|
||||
_ampsXY = new Vector2(10, 10);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (_fishing) {
|
||||
if (!_catchable) {
|
||||
_fishCooldown += Time.deltaTime;
|
||||
if (_spawnFish && _fishCooldown >= _totalFishCooldown && Random.Range(0, 100) <= 1) {
|
||||
_spawnFish = false;
|
||||
//particles for fish -> catchable true
|
||||
|
||||
if (_fishing) { //Fishing
|
||||
if (!_catchable) { // Fish not spawned yet
|
||||
_fishCooldown -= Time.deltaTime;
|
||||
if (_fishCooldown <= 0) { //fish will get spawned
|
||||
_catchable = true;
|
||||
if (!_exMark.activeSelf) {
|
||||
_exMark.SetActive(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!_caught) {
|
||||
_fishingTime += Time.deltaTime;
|
||||
}
|
||||
_fishingTime += Time.deltaTime;
|
||||
//NotifyShake();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyShake() {
|
||||
_exMark.transform.position =
|
||||
new Vector3(_exMark.transform.position.x * _ampsXY.x * Time.deltaTime,
|
||||
_exMark.transform.position.y * _ampsXY.y * Time.deltaTime,
|
||||
transform.position.z);
|
||||
_ampsXY.x *= -1;
|
||||
_ampsXY.y *= -1;
|
||||
}
|
||||
|
||||
private void ResetFishing() {
|
||||
_fishing = false;
|
||||
_catchable = false;
|
||||
_fishingTime = 0f;
|
||||
_fishCooldown = 1.5f;
|
||||
_spawnFish = true;
|
||||
_fishCooldown = Random.Range(_minFishCooldown, _maxFishCooldown);
|
||||
_exMark.SetActive(false);
|
||||
}
|
||||
|
||||
public void StartFishing() {
|
||||
Vector3 pos = Input.mousePosition;
|
||||
|
||||
if (Camera.main != null) {
|
||||
float newPosX = pos.x;
|
||||
float newPosY;
|
||||
|
||||
if (pos.y - 50 - ((RectTransform)_exMark.transform).rect.height >= 0) { //check if bottom of panel is in screen
|
||||
newPosY = pos.y - ((RectTransform)_exMark.transform).rect.height;
|
||||
} else {
|
||||
newPosY = pos.y + ((RectTransform)_exMark.transform).rect.height;
|
||||
}
|
||||
|
||||
_exMark.transform.position = new Vector3(newPosX, newPosY);
|
||||
}
|
||||
_fishing = true;
|
||||
}
|
||||
|
||||
public void TryCatch() {
|
||||
if (_fishing && _catchable) {
|
||||
Debug.Log("Tried to catch!");
|
||||
if (_fishingTime <= _maxTime) {
|
||||
_fishing = false;
|
||||
_caught = true;
|
||||
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3/_fishingTime));
|
||||
Debug.Log("Caught!");
|
||||
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3 / _fishingTime));
|
||||
ResetFishing();
|
||||
} else {
|
||||
_spawnFish = true;
|
||||
Debug.Log("Failed to catch!");
|
||||
_catchable = false;
|
||||
_fishingTime = 0f;
|
||||
_exMark.SetActive(false);
|
||||
_fishCooldown = Random.Range(_minFishCooldown+2, _maxFishCooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue