Winner is coming
We now have all the information we need to check the Squares, to determine which piece they contain, and to call the match if we find 3-in-a-row. In the GameLogic
script, scaffold the mighty hard-fought CheckForWin
function:
function CheckForWin(square:GameObject):boolean { }
Did you notice something different about this function declaration? It's got a big, ugly boolean
stuck to the side of its face. (Gee—it should really get that looked at).
This function declares a return type. We've already called numerous functions that have a return value, but this is the first time we've set one up in our own custom code. All it means is that somewhere along the way, this function will spit out a boolean value. In fact, it must spit out a boolean value, or else we'll get script error.
To spit out a value, we'll use the return
keyword. This CheckForWin
function must, at some point, return either true
or false
, or a statement that resolves to true or false, such as (2+2)==4
(true!) or...