Game Development Reference
In-Depth Information
Figure 14.6 Using Debug to
check if the raycasting is working as
anticipated.
Tips and Tricks
Note that in Figure 14.6 the Collapse button is clicked in the Console.
The script (as it now exists) is checking for the name of objects the ray is
colliding with every single frame. This means that there will be 30 Debug
.Log's per second (at least) showing up in the Console making it hard to
read much of what's going on. The Collapse button collapses repeating
warnings or Debug.Logs into one entry making it a bit easier to see what's
happening down there.
Why?
Why bother with these Debug thingies? True, true, Debug anything
is most often used when trying to squash bugs, and in fact can be a
very important part of trying to figure out if a script is going wrong
and where it's going wrong. However, I find that using some basic
Debug stuff early on in the process of developing a script helps me
find out if the early drafts of the script are doing what I think they're
doing. In fact, for some really elegant Debug stuff, try changing the last
line to Debug.Log (“Selected object is ” + hit.collider.
gameObject.name);
Step 8: Create an independent highlighting function. Further down from
the function Update create a new function that reads thusly:
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform
.forward, hit, 100)){
Debug.DrawLine (transform.position, hit
Search WWH ::




Custom Search