リファクタ

This commit is contained in:
kimura 2021-07-07 16:32:58 +09:00
parent 77f85b3a6a
commit fda7226d6c
2 changed files with 9 additions and 8 deletions

View File

@ -5,14 +5,15 @@ public class Pan : MonoBehaviour
{ {
[SerializeField] private PanController controller; [SerializeField] private PanController controller;
[SerializeField] private float thrust; [SerializeField] private float thrust;
private static readonly float deadZone = 0.1f;
private void OnTriggerStay2D(Collider2D other) private void OnTriggerStay2D(Collider2D other)
{ {
// Debug.Log(controller.Direction);
// 移動量が少ないときは動かない // 移動量が少ないときは動かない
// if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude); if (controller.Delta.magnitude < deadZone)
var direct = 1f; {
direct = controller.Delta.magnitude < 0.1f ? 0 : 1; return;
other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse); }
other.attachedRigidbody.AddForce(controller.Delta * thrust, ForceMode2D.Impulse);
} }
} }

View File

@ -34,6 +34,9 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
delta = Vector2.zero; delta = Vector2.zero;
} }
prevPos = target.position; prevPos = target.position;
#if UNITY_EDITOR
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
#endif
} }
@ -45,9 +48,6 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
// 移動範囲を制限 // 移動範囲を制限
pos = targetBorder.bounds.ClosestPoint(pos); pos = targetBorder.bounds.ClosestPoint(pos);
delta = pos - targetPos; delta = pos - targetPos;
#if UNITY_EDITOR
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
#endif
target.position = pos; target.position = pos;
} }