151 lines
3.1 KiB
C#
151 lines
3.1 KiB
C#
using UnityEngine;
|
|
|
|
public class BaitStats : MonoBehaviour
|
|
{
|
|
public enum BaitType
|
|
{
|
|
None = 0,
|
|
Feed = 1,
|
|
LiveFish = 2,
|
|
Hook = 3,
|
|
Lure = 4
|
|
}
|
|
|
|
[Tooltip("none-nieznana łapie w pyski i puszcza, feed-zaneta zjada odrazu, LiveFish-małe rybki zjada odrazu, Hook-haczyk z przynetą")]
|
|
public BaitType baitType;
|
|
|
|
public int baitID = -1;
|
|
|
|
public bool isDisabled;
|
|
|
|
private float timeDelayDisabled;
|
|
|
|
private Rigidbody _rigidbody;
|
|
|
|
private WaterDisplacementObject waterInteractive;
|
|
|
|
private Collider collider;
|
|
|
|
[HideInInspector]
|
|
public Vector3 deepProbe;
|
|
|
|
[HideInInspector]
|
|
public Hook hook;
|
|
|
|
[HideInInspector]
|
|
public Lure lure;
|
|
|
|
public Vector3 baitInJawPosition;
|
|
|
|
public Vector3 baitInJawRotation;
|
|
|
|
private void Start()
|
|
{
|
|
_rigidbody = GetComponent<Rigidbody>();
|
|
waterInteractive = GetComponent<WaterDisplacementObject>();
|
|
collider = GetComponent<Collider>();
|
|
if (baitType == BaitType.Hook)
|
|
{
|
|
hook = GetComponent<Hook>();
|
|
}
|
|
if (baitType == BaitType.Lure)
|
|
{
|
|
lure = GetComponent<Lure>();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isDisabled)
|
|
{
|
|
timeDelayDisabled = Mathf.MoveTowards(timeDelayDisabled, 5f, Time.deltaTime);
|
|
if (timeDelayDisabled == 5f)
|
|
{
|
|
timeDelayDisabled = 0f;
|
|
isDisabled = false;
|
|
}
|
|
}
|
|
deepProbe = waterInteractive.deepProbe;
|
|
}
|
|
|
|
public void SetBaitOnFishJaw(FishStats fish)
|
|
{
|
|
if (base.transform.parent != null)
|
|
{
|
|
return;
|
|
}
|
|
if (hook != null)
|
|
{
|
|
if ((bool)hook.takeFish)
|
|
{
|
|
return;
|
|
}
|
|
hook.takeFish = fish;
|
|
}
|
|
else if (lure != null)
|
|
{
|
|
if ((bool)lure.takeFish)
|
|
{
|
|
return;
|
|
}
|
|
lure.takeFish = fish;
|
|
}
|
|
Transform jawJointPoint = fish.fishObjectConfig.JawJointPoint;
|
|
waterInteractive.enabled = false;
|
|
if ((bool)hook)
|
|
{
|
|
_rigidbody.isKinematic = true;
|
|
base.transform.SetParent(jawJointPoint);
|
|
base.transform.localPosition = Vector3.zero;
|
|
base.transform.localEulerAngles = Vector3.zero;
|
|
fish.gameObject.AddComponent<FixedJoint>().connectedBody = hook.rigidbody;
|
|
collider.enabled = false;
|
|
}
|
|
else if ((bool)lure)
|
|
{
|
|
_rigidbody.isKinematic = true;
|
|
base.transform.SetParent(jawJointPoint);
|
|
base.transform.localEulerAngles = Vector3.zero;
|
|
base.transform.localPosition = Vector3.zero;
|
|
fish.gameObject.AddComponent<FixedJoint>().connectedBody = lure.rigidbody;
|
|
collider.enabled = false;
|
|
}
|
|
else
|
|
{
|
|
base.transform.SetParent(jawJointPoint);
|
|
base.transform.localPosition = Vector3.zero;
|
|
base.transform.localEulerAngles = Vector3.zero;
|
|
collider.enabled = false;
|
|
_rigidbody.isKinematic = true;
|
|
}
|
|
}
|
|
|
|
public void SetBaitOffFishJaw()
|
|
{
|
|
base.transform.SetParent(null);
|
|
collider.enabled = true;
|
|
_rigidbody.isKinematic = false;
|
|
waterInteractive.enabled = true;
|
|
isDisabled = true;
|
|
if (hook != null)
|
|
{
|
|
if ((bool)hook.takeFish)
|
|
{
|
|
if ((bool)hook.takeFish.GetComponent<FixedJoint>())
|
|
{
|
|
Object.Destroy(hook.takeFish.GetComponent<FixedJoint>());
|
|
}
|
|
hook.takeFish = null;
|
|
}
|
|
}
|
|
else if (lure != null && (bool)lure.takeFish)
|
|
{
|
|
if ((bool)lure.takeFish.GetComponent<FixedJoint>())
|
|
{
|
|
Object.Destroy(lure.takeFish.GetComponent<FixedJoint>());
|
|
}
|
|
lure.takeFish = null;
|
|
}
|
|
}
|
|
}
|