using System.Collections; using Obvious.Soap; using SoapCustomVariable; using UnityEngine; public class BobberController : MonoBehaviourExtended { [SerializeField] private FSMVariable playerState; [OwnComponent(0)] private Rigidbody _rbody; private ConfigurableJoint joint; public FloatVariable bobberScaleSetting; [OwnComponent(0)] private Buoyancy _buoyancy; public Rigidbody rbody => _rbody; private IEnumerator Start() { _rbody.detectCollisions = false; BobberScaleSettingOnOnValueChanged(bobberScaleSetting.Value); yield return new WaitForSeconds(2f); _rbody.detectCollisions = true; } private void OnEnable() { bobberScaleSetting.OnValueChanged += BobberScaleSettingOnOnValueChanged; } private void OnDisable() { bobberScaleSetting.OnValueChanged -= BobberScaleSettingOnOnValueChanged; } private void BobberScaleSettingOnOnValueChanged(float size) { base.transform.localScale = Vector3.one * size; } public void SetDetectCollisionEnabled(bool enabled) { _rbody.detectCollisions = enabled; _buoyancy.EnablePhysics(enabled); } public void SetVelocity(Vector3 velocity) { _rbody.linearVelocity = velocity; } private void WaterFloater_OnWaterEnter(bool obj) { if (obj) { StartCoroutine(MoveRotate()); } else { StopCoroutine(MoveRotate()); } static IEnumerator MoveRotate() { while (true) { yield return null; } } } public void SetKinematic(bool value) { GetComponent().isKinematic = value; } public void SetJoint(Rigidbody rb) { joint = ((joint == null) ? GetComponent() : joint); joint.connectedBody = rb; } }