Game Development Reference
In-Depth Information
(_boxCollider2D.size.x*CHARACTER_EDGE_OFFSET),
transform.position.y);
Vector2 origin = new Vector2(transform.position.x,
transform.position.y);
if (Physics2D.Raycast (origin, hitDirection,
distance, layerMask.value)) {
_isGrounded = true;
} else if (Physics2D.Raycast (rightOrigin,
hitDirection, distance, layerMask.value)) {
_isGrounded = true;
} else if (Physics2D.Raycast (leftOrigin,
hitDirection, distance, layerMask.value)) {
_isGrounded = true;
} else {
if (_isGrounded) {
if (Mathf.Floor(transform.position.y) ==
_lastY) {
_isGrounded = true;
} else {
_isGrounded = false;
}
}
}
_lastY = Mathf.Floor(transform.position.y);
}
8. Next, we will include the script in the Update() function and LateUpdate()
function that get called after the Update() function. These functions will be
used to check the input from the user and update the camera to follow our charac-
ter movement. The code for these functions are as follows:
// Unity JavaScript user:
function Update() {
if (!_gameEnd) {
_horizontalInput = Input.GetAxis("Horizontal");
if ((!_isFacingRight && (_horizontalInput > 0))
||
(_isFacingRight && (_horizontalInput < 0))) {
Search WWH ::




Custom Search