Search Unity

Raycast hit convert code in Raycast2D

Discussion in '2D' started by roshan090, Jun 18, 2019.

  1. roshan090

    roshan090

    Joined:
    Mar 20, 2018
    Posts:
    35
    i am not very good in raycast. can someone please help me to convert these line of code in 2D

    RaycastHit hit;
    if (Physics.Raycast(transform.position, direction, out hit, 100f))
    {
    nextCollisionPosition = hit.point;
    Debug.Log(hit.collider.name);
    }
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Why not just use Physics2D.Raycast and RaycastHit2D?

    Edit:
    Also, please do not spam threads. You don't need to ask the same question in multiple subforums.