FishingController.cs finished
This commit is contained in:
parent
9e91220be4
commit
cf8851745d
3 changed files with 271 additions and 26 deletions
|
|
@ -12,9 +12,8 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 5f096d187f76a734fac022700054dfec, type: 3}
|
||||
m_Name: Fish
|
||||
m_EditorClassIdentifier:
|
||||
displayName:
|
||||
description:
|
||||
id: 0
|
||||
selectedSprite: {fileID: 0}
|
||||
defaultSprite: {fileID: 0}
|
||||
cost: 0
|
||||
displayName: Fish
|
||||
description: Used to slap people.
|
||||
selectedSprite: {fileID: 21300000, guid: 8c01c1a230575ac4bb0aee5ba1c7757a, type: 3}
|
||||
defaultSprite: {fileID: 21300000, guid: d1b54b7f17e2d4d4e82d50d710d4482c, type: 3}
|
||||
cost: 150
|
||||
|
|
|
|||
|
|
@ -1972,6 +1972,83 @@ CanvasRenderer:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 656110740}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &656860534
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 656860535}
|
||||
- component: {fileID: 656860537}
|
||||
- component: {fileID: 656860536}
|
||||
m_Layer: 5
|
||||
m_Name: FishingParent
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &656860535
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 656860534}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 2090400144}
|
||||
m_Father: {fileID: 1061398534}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 1}
|
||||
m_AnchorMax: {x: 0, y: 1}
|
||||
m_AnchoredPosition: {x: 40, y: -179.4}
|
||||
m_SizeDelta: {x: 50, y: 50}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &656860536
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 656860534}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 21300000, guid: 349d3f5d7a4156146b8e923d5c06314d, type: 3}
|
||||
m_Type: 1
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &656860537
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 656860534}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1001 &729139770
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -3652,6 +3729,7 @@ RectTransform:
|
|||
m_Children:
|
||||
- {fileID: 1070476668}
|
||||
- {fileID: 1649897726}
|
||||
- {fileID: 656860535}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
|
@ -6817,6 +6895,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 00d85fb65e728cd429cb33d865a5d31a, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_exMark: {fileID: 656860534}
|
||||
--- !u!1001 &1805366398
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -7986,6 +8065,141 @@ PrefabInstance:
|
|||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3}
|
||||
--- !u!1 &2090400143
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2090400144}
|
||||
- component: {fileID: 2090400146}
|
||||
- component: {fileID: 2090400145}
|
||||
m_Layer: 5
|
||||
m_Name: ExMark
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &2090400144
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2090400143}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 656860535}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 50, y: 50}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &2090400145
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2090400143}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: '!'
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
|
||||
m_fontSharedMaterials: []
|
||||
m_fontMaterial: {fileID: 0}
|
||||
m_fontMaterials: []
|
||||
m_fontColor32:
|
||||
serializedVersion: 2
|
||||
rgba: 4280045691
|
||||
m_fontColor: {r: 0.48235297, g: 0.3137255, b: 0.10980393, a: 1}
|
||||
m_enableVertexGradient: 0
|
||||
m_colorMode: 3
|
||||
m_fontColorGradient:
|
||||
topLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
topRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
|
||||
bottomRight: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_fontColorGradientPreset: {fileID: 0}
|
||||
m_spriteAsset: {fileID: 0}
|
||||
m_tintAllSprites: 0
|
||||
m_StyleSheet: {fileID: 0}
|
||||
m_TextStyleHashCode: -1183493901
|
||||
m_overrideHtmlColors: 0
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 40
|
||||
m_fontSizeBase: 40
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 0
|
||||
m_fontSizeMin: 18
|
||||
m_fontSizeMax: 72
|
||||
m_fontStyle: 9
|
||||
m_HorizontalAlignment: 2
|
||||
m_VerticalAlignment: 512
|
||||
m_textAlignment: 65535
|
||||
m_characterSpacing: 0
|
||||
m_wordSpacing: 0
|
||||
m_lineSpacing: 0
|
||||
m_lineSpacingMax: 0
|
||||
m_paragraphSpacing: 0
|
||||
m_charWidthMaxAdj: 0
|
||||
m_enableWordWrapping: 1
|
||||
m_wordWrappingRatios: 0.4
|
||||
m_overflowMode: 0
|
||||
m_linkedTextComponent: {fileID: 0}
|
||||
parentLinkedComponent: {fileID: 0}
|
||||
m_enableKerning: 1
|
||||
m_enableExtraPadding: 0
|
||||
checkPaddingRequired: 0
|
||||
m_isRichText: 1
|
||||
m_parseCtrlCharacters: 1
|
||||
m_isOrthographic: 1
|
||||
m_isCullingEnabled: 0
|
||||
m_horizontalMapping: 0
|
||||
m_verticalMapping: 0
|
||||
m_uvLineOffset: 0
|
||||
m_geometrySortingOrder: 0
|
||||
m_IsTextObjectScaleStatic: 0
|
||||
m_VertexBufferAutoSizeReduction: 0
|
||||
m_useMaxVisibleDescender: 1
|
||||
m_pageToDisplay: 1
|
||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_isUsingLegacyAnimationComponent: 0
|
||||
m_isVolumetricText: 0
|
||||
m_hasFontAssetChanged: 0
|
||||
m_baseMaterial: {fileID: 0}
|
||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
|
||||
--- !u!222 &2090400146
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2090400143}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &2091640948
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -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