Game Development Reference
In-Depth Information
Figure 14.4 Scripting reference for
Physics.Raycast.
That line reads:
static function Raycast (origin : Vector3 , direction :
Vector3 , distance : float = Mathf.Infinity , layerMask :
int = kDefaultRaycastLayers) : bool
There's a lot of stuff there, but here's how to interpret it. Raycast has several
parameters that are definable. Those parameters are laid out within the (). Each
of the parameters are separated by a comma. Each of these parameters are
typed with the colon. So for instance, the first parameter is the “origin” of the
ray and this value must be a Vector3; the second parameter is the “direction” of
the ray, which is also expressed as a Vector3; the third is the “distance” the ray
casts and will be written as a float, which means it can contain decimals; finally,
the fourth parameter is the layerMask (which layers to ignore when casting the
ray), which will be expressed as an integer (layers are numbered).
Further down the page are other formats where this class can be used. These will
include other parameters that can be expressed and the order in which they must
be expressed. So for instance, a little way down the page, the following appears:
static function Raycast (origin : Vector3 , direction :
Vector3 , out hitInfo : RaycastHit , distance : float =
Mathf.Infinity , layerMask : int = kDefaultRaycastLayers) :
bool
Notice that it has the same parameters of the origin, the direction, but then
includes a parameter for something called a RaycastHit, which is a variable
that will be used to hold information about the things the ray hits. Later if we
want to (and we will) we can access this RaycastHit and check the name of the
object or find its exact location. This is followed by distance and layer mask.
Search WWH ::




Custom Search