Game Development Reference
In-Depth Information
Classified intel
At the
Waypoint
script, we use the following lines in the
OnDrawGizmos()
function
to get both values from the
WaypointsContainer
script as follows:
// Unity JavaScript user:
_showGizmos =
transform.parent.GetComponent.<WaypointsContainer>().showPath;
_radius =
transform.parent.GetComponent.<WaypointsContainer>().radius;
// C# user:
_showGizmos =
transform.parent.GetComponent<WaypointsContainer>().showPath;
_radius =
transform.parent.GetComponent<WaypointsContainer>().radius;
This function is called
generic functions
, which is usually known to the C# user. However,
for the JavaScript user, this might be a new thing. This is basically the function that can be
called to return the strict type. It means that we don't need to cast the type, as we can see in
the following pseudo code:
Function FunctionName.<T>() : T;
This is very useful if we want to get around the limitations of dynamic tying in JavaScript,
as shown in the following code:
var obj = GetComponent.<Transform>();
From the preceding code,
obj
will be the
Transform
type. However, if we use
GetCompent(Transform)
, the
obj
type will be the
Component
type.