Tag Archives: 2d

[Unity3D] RaycastHit2D

void Update () {

        Debug.DrawRay(transform.position, Vector3.forward, Color.red, 50.0f);

        RaycastHit2D hit =  Physics2D.Raycast(transform.position, Vector3.forward, 50.0f);

        if (hit.collider != null && hit.collider.name != lastCollName)
        {
            lastCollName = hit.collider.name;
            Debug.Log(string.Format("[RaycastHit2D] {0}:{1}", transform.parent.name, hit.collider.name));         
        }
        
	}