97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using UnityEngine;
|
|
|
|
public class Float : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public Rigidbody linkConnectorUp;
|
|
|
|
public HingeJoint hingeJointUp;
|
|
|
|
[HideInInspector]
|
|
public FishingLine currentFishingLine;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody rigidbody;
|
|
|
|
[HideInInspector]
|
|
public WaterDisplacementObject waterDisplacementObject;
|
|
|
|
[HideInInspector]
|
|
public float currentFloatDeepth = 0.15f;
|
|
|
|
public ParticleSystem smuuggeParticle;
|
|
|
|
private void Start()
|
|
{
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
waterDisplacementObject = GetComponent<WaterDisplacementObject>();
|
|
if (smuuggeParticle != null && smuuggeParticle.isPlaying)
|
|
{
|
|
smuuggeParticle.Stop();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
SetDeepth();
|
|
ShowWaterFX();
|
|
}
|
|
|
|
public void Link(Rigidbody connector)
|
|
{
|
|
if (connector.transform.parent.GetComponent<LineHandler>().lineType == LineHandler.LineType.TwoSegment)
|
|
{
|
|
currentFishingLine = connector.transform.parent.GetComponent<LineHandler>().currentRodFishingLineComponent;
|
|
if (!(currentFishingLine.fishingFloat != this))
|
|
{
|
|
currentFishingLine.fishingFloat = this;
|
|
linkConnectorUp = connector;
|
|
base.transform.position = linkConnectorUp.position;
|
|
hingeJointUp.connectedBody = linkConnectorUp;
|
|
currentFishingLine.currentLineHandler.SetSegmentTwoLenght(currentFloatDeepth);
|
|
linkConnectorUp.GetComponent<MeshRenderer>().enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetDeepth()
|
|
{
|
|
if (!(currentFishingLine.hook.waterDisplacementObject.deepProbe.z > 0f))
|
|
{
|
|
if (InputManager.isDeepthFloatUp)
|
|
{
|
|
currentFloatDeepth += 0.1f;
|
|
currentFloatDeepth = Mathf.Clamp(currentFloatDeepth, 0.15f, 2f);
|
|
currentFishingLine.currentLineHandler.SetSegmentTwoLenght(currentFloatDeepth);
|
|
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + currentFloatDeepth.ToString("F1") + " m", ScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
|
}
|
|
if (InputManager.isDeepthFloatDown)
|
|
{
|
|
currentFloatDeepth -= 0.1f;
|
|
currentFloatDeepth = Mathf.Clamp(currentFloatDeepth, 0.15f, 2f);
|
|
currentFishingLine.currentLineHandler.SetSegmentTwoLenght(currentFloatDeepth);
|
|
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + currentFloatDeepth.ToString("F1") + " m", ScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowWaterFX()
|
|
{
|
|
if (smuuggeParticle == null)
|
|
{
|
|
return;
|
|
}
|
|
if (base.transform.position.y >= waterDisplacementObject.waterHeightPosition - 0.05f && base.transform.position.y <= waterDisplacementObject.waterHeightPosition + 0.05f && !currentFishingLine.hook.takeFish && rigidbody.velocity.magnitude > 0.1f)
|
|
{
|
|
if (!smuuggeParticle.isEmitting)
|
|
{
|
|
smuuggeParticle.Play();
|
|
}
|
|
}
|
|
else if (smuuggeParticle.isPlaying)
|
|
{
|
|
smuuggeParticle.Stop();
|
|
}
|
|
}
|
|
}
|