Commit 2314940d authored by 15박보승's avatar 15박보승

훅의 최대거리 제한 구현

parent df67be5d
......@@ -342,6 +342,7 @@ MonoBehaviour:
lr: {fileID: 48712148}
player: {fileID: 1171556388}
rb: {fileID: 0}
maxDistance: 200
--- !u!1 &60348332
GameObject:
m_ObjectHideFlags: 0
......
......@@ -12,7 +12,12 @@ public class HookBehaviour : MonoBehaviour
[SerializeField]
private Rigidbody rb;
private void OnDrawGizmos()
[SerializeField]
private float maxDistance;
private float curDistance;
private void OnDrawGizmos()
{
}
......@@ -29,6 +34,17 @@ public class HookBehaviour : MonoBehaviour
lr.SetPosition(1, player.position);
}
private void FixedUpdate()
{
Debug.Log(curDistance);
if (curDistance <= maxDistance)
{
curDistance += rb.velocity.magnitude * Time.fixedDeltaTime;
if (curDistance > maxDistance)
player.GetComponent<PlayerController>().ReturnHook();
}
}
private void OnCollisionEnter(Collision collision)
{
rb.velocity = Vector3.zero;
......@@ -43,6 +59,7 @@ public class HookBehaviour : MonoBehaviour
lr.SetPosition(1, player.position);
rb.isKinematic = false;
rb.velocity = velocity;
curDistance = 0;
}
public void DisableHook()
......
......@@ -36,6 +36,7 @@ public class PlayerController : MonoBehaviour
[SerializeField]
private LayerMask enemyMask;
#if UNITY_EDITOR
private void OnDrawGizmos()
{
......@@ -120,7 +121,7 @@ public class PlayerController : MonoBehaviour
hook.EnableHook(Camera.main.transform.forward.normalized * 200);
}
private void ReturnHook()
public void ReturnHook()
{
joint.enabled = false;
hook.DisableHook();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment