//Check if the difference along the x axis is greater than the difference along the y axis.
if (Mathf.Abs(x) > Mathf.Abs(y))
//If x is greater than zero, set horizontal to 1, otherwise set it to -1
horizontal = x > 0 ? 1 : -1;
else
//If y is greater than zero, set horizontal to 1, otherwise set it to -1
vertical = y > 0 ? 1 : -1;
}
}
#endif //End of mobile platform dependendent compilation section started above with #elif
//Check if we have a non-zero value for horizontal or vertical
if(horizontal != 0 || vertical != 0)
{
//Call AttemptMove passing in the generic parameter Wall, since that is what Player may interact with if they encounter one (by attacking it)
//Pass in horizontal and vertical as parameters to specify the direction to move Player in.
AttemptMove (horizontal, vertical);
}
}
//AttemptMove overrides the AttemptMove function in the base class MovingObject
//AttemptMove takes a generic parameter T which for Player will be of the type Wall, it also takes integers for x and y direction to move in.
protected override void AttemptMove (int xDir, int yDir)
{
//Every time player moves, subtract from food points total.
food--;
//Update food text display to reflect current score.
foodText.text = "Food: " + food;
//Call the AttemptMove method of the base class, passing in the component T (in this case Wall) and x and y direction to move.
base.AttemptMove (xDir, yDir);
//Hit allows us to reference the result of the Linecast done in Move.
RaycastHit2D hit;
//If Move returns true, meaning Player was able to move into an empty space.
if (Move (xDir, yDir, out hit))
{
//Call RandomizeSfx of SoundManager to play the move sound, passing in two audio clips to choose from.
SoundManager.instance.RandomizeSfx (moveSound1, moveSound2);
}
//Since the player has moved and lost food points, check if the game has ended.
CheckIfGameOver ();
//Set the playersTurn boolean of GameManager to false now that players turn is over.
GameManager.instance.playersTurn = false;
}
ÁÖÀΰøÀÇ À̵¿°ú °ü·ÃÇØ ¾Æ¹«¸® º¸¾Æµµ
if (Mathf.Abs(x) > Mathf.Abs(y))
//If x is greater than zero, set horizontal to 1, otherwise set it to -1
horizontal = x > 0 ? 1 : -1;
else
//If y is greater than zero, set horizontal to 1, otherwise set it to -1
vertical = y > 0 ? 1 : -1;
À̺κÐÀÌ, µå·¡±× ¹æ½ÄÀÇ ÁÖÀΰø À̵¿ ÀεíÇÏ¿©
protected override void AttemptMove (int xDir, int yDir)
ÀÌ°ÍÀÌ x,y¸¦ ³Ñ°Ü¼ ½ÇÁ¦·Î À̵¿ÇÏ´Â °ÍÀÌ°ÚÁÒ.
µå·¡±×°¡ ¾Æ´Ñ, UGUI ¹öÆ° 4°³¸¦ ¸¸µé¾î, °¢°¢ horizontal vertical ¿¡, 1,-1¸¦ ´ëÀÔÇÏ·Á°í Çϴµ¥
ȸ鿡 UGUI ¹öÆ° 4°³´Â ¸¸µé¾ú´Âµ¥, 1, ÀÌ°ÍÀÌ ÅÍÄ¡ µÇ¾ú´Ù , 2, ±×·¯¸é horizontalÀÇ °ªÀ» ¹Ù²Û´Ù.
ÀÌ ½ºÅ©¸³Æ®¸¦ ¾²°í½ÍÀºµ¥, ¾î¶»°Ô ½á¾ß ÇÒÁö ¸ð¸£°Ú¾î¼.. Áú¹®À» ¿Ã¸³´Ï´Ù. | |
|
switch()
case 1:
}
?????