Game Development Reference
In-Depth Information
// Unity JavaScript user:
private function Flip () {
_isFacingRight = !_isFacingRight;
var scale : Vector3 = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}
// C# user: (Put the code inside the class)
void Flip () {
_isFacingRight = !_isFacingRight;
Vector3 scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
}
7. Next, we will add another function, which will use Physics2D.Raycast to
check whether the player is on the ground or not. Let's create the Grounded()
function as follows:
// Unity JavaScript user:
private function Grounded () {
var distance : float = _height*RAYCAST_DISTANCE;
var hitDirectionV3 : Vector3 =
transform.TransformDirection(-Vector3.up);
var hitDirection : Vector2 = new
Vector2(hitDirectionV3.x,hitDirectionV3.y);
var rightOrigin : Vector2 = new
Vector2(transform.position.x +
(_boxCollider2D.size.x*CHARACTER_EDGE_OFFSET),
transform.position.y);
var leftOrigin : Vector2 = new
Vector2(transform.position.x -
(_boxCollider2D.size.x*CHARACTER_EDGE_OFFSET),
transform.position.y);
Search WWH ::




Custom Search