Answers for "2d raycast algorithm"

C#
0

raycast 2d

using UnityEngine

public class ExampleClass : MonoBehaviour
{
    
    void FixedUpdate()
    {
         RaycastHit2D hit;
        if (Physics2D.Raycast2D(transform.position, transform.TransformDirection(Vector2.forward), out hit, 10))
        {
            
            Debug.Log(hit.gameobject);
        }
        else
        {
            
            Debug.Log("Did not Hit");
        }
    }
}
Posted by: Guest on August-22-2021

C# Answers by Framework

Browse Popular Code Answers by Language