リファクタ
This commit is contained in:
parent
77f85b3a6a
commit
fda7226d6c
|
|
@ -5,14 +5,15 @@ public class Pan : MonoBehaviour
|
|||
{
|
||||
[SerializeField] private PanController controller;
|
||||
[SerializeField] private float thrust;
|
||||
private static readonly float deadZone = 0.1f;
|
||||
|
||||
private void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
// Debug.Log(controller.Direction);
|
||||
// 移動量が少ないときは動かない
|
||||
// if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude);
|
||||
var direct = 1f;
|
||||
direct = controller.Delta.magnitude < 0.1f ? 0 : 1;
|
||||
other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse);
|
||||
if (controller.Delta.magnitude < deadZone)
|
||||
{
|
||||
return;
|
||||
}
|
||||
other.attachedRigidbody.AddForce(controller.Delta * thrust, ForceMode2D.Impulse);
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,9 @@ public class PanController : MonoBehaviour, IDragHandler, IBeginDragHandler
|
|||
delta = Vector2.zero;
|
||||
}
|
||||
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);
|
||||
delta = pos - targetPos;
|
||||
#if UNITY_EDITOR
|
||||
deltaString = $"delta: {delta.normalized} {delta.magnitude:F3}";
|
||||
#endif
|
||||
target.position = pos;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue