using UnityEngine; using System.Collections; public class RaycastTester : MonoBehaviour { public GameObject target; public float distance = 100; // Use this for initialization void Start () { } private void FixedUpdate() { if (target != null) { var src = transform.position; var dst = target.transform.position; var hit = Physics2D.Raycast(src, (dst - src).normalized, distance, 1 << target.gameObject.layer); if (hit.rigidbody != null) { Debug.Log("!!!Hit collider: " + hit.collider.name); } else { Debug.Log("!!!Nothing hit"); } Debug.DrawLine(src, dst); } } // Update is called once per frame void Update () { } }