Game Development Reference
In-Depth Information
Gizmos.DrawRay(v3_left, transform.TransformDirection (-Vector3.
up) * (f_height * 0.5));
}
6. Finally , we add another SpriteManager class, which is a litle diferent from our
first sprite class. This SpriteManager is for our jumping animaion. Since our
jumping animaion is quite unique and not a loop animaion, we need another sprite
class to control it. Let's add this code underneath our SpriteManager class and call
it JumpSpriteManager :
class JumpSpriteManager {
public var t_jumpStartTexture : Texture2D; //Alternative Jump
Texture play after t_jumpReadyTextures
public var t_jumpAirTexture : Texture2D; //Alternative Jump
Texture play when the player in the air at the top position of
projectile
public var t_jumpDownTexture : Texture2D; //Alternative Jump
Texture play when the player fall to the ground
public function updateJumpAnimation (_direction : int, _
velocityY : float, _material : Material) : void {
//Checking for the player position in the air
if ((_velocityY>= -2.0) && (_velocityY<= 2.0)) { //Top of the
projectile
_material.mainTexture =t_jumpAirTexture;
} else if (_velocityY> 2.0) { //Start Jump
_material.mainTexture = t_jumpStartTexture;
} else { //Fall
_material.mainTexture = t_jumpDownTexture;
}
_material.mainTextureScale = new Vector2 (_direction * 1, 1);
_material.mainTextureOffset = new Vector2 (_direction * 1, 1);
}
}
7. Now we are done with coding, go back to Unity, go to Hierarchy , and click on our
Player , then go to the Inspector view. Now, we will see a new parameter Jump
Sprite ; click on it to get the parameters, then set the following:
T_jump Start Texture : J_Frame1
T_jump Air Texture : J_Frame2
T_jump Down Texture : J_Frame3
Layer Mask : Level
We have now finished this step. Let's click plays the game and Space on the keyboard. Now,
you will see your Player Jumping.
 
Search WWH ::




Custom Search