private ViewCastInfo ViewCast(float angle) { // create and initialize a ViewCastInfo ViewCastInfo info = new ViewCastInfo(); Vector2 direction = ExtraMath.AngleToVector2(angle); info.Point = _targetManager.transform.position + (Vector3)direction * _targetManager.VisionRange; info.Distance = _targetManager.VisionRange; info.Angle = angle; // check if something was hit RaycastHit2D hit = Physics2D.Raycast(_targetManager.transform.position, direction, _targetManager.VisionRange, _targetManager.VisionLayers); // if something was hit, modify the ViewCastInfo if (hit.transform != null) { info.Hit = true; info.Point = hit.point; info.Distance = hit.distance; } return(info); }