I m working on the simple 2D game project and it have building system like you can place walls, platforms, etc. I m using RaycastHit2D to detect collision, but the problem is that if the raycast doesn’t hit anything on its way then how to get the end point of the ray?
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Private float distance = 2.4f;
Private Vector2 endPoint;
private void FixedUpdate(){
RaycastHit2D hit = Physics2D.Raycast(transform.position,
Vector2.right, distance);
if(hit.collider == null){
//how to get the end point co-ordinate of the ray?
}
}
}