void Start() { rigidBody = this.gameObject.GetComponent <Rigidbody2D> (); oldGravityScale = this.GetComponent <Rigidbody2D> ().gravityScale; currentSide = CurrentSide.LEFT; anim = this.GetComponent <Animator> (); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == tagColliderName) { this.GetComponent <Rigidbody2D> ().gravityScale = 0; this.GetComponent <Rigidbody2D> ().velocity = new Vector2(0, this.GetComponent <Rigidbody2D>().velocity.y); if (currentSide == CurrentSide.LEFT) { float xPos = other.transform.position.x; xPos -= .2f; Vector3 newPosition = this.gameObject.transform.position; newPosition.x = xPos; this.gameObject.transform.position = newPosition; } else if (currentSide == CurrentSide.RIGHT) { float xPos = other.transform.position.x; xPos += .2f; Vector3 newPosition = this.gameObject.transform.position; newPosition.x = xPos; this.gameObject.transform.position = newPosition; } } if (other.gameObject.tag == tagColliderName && isJumping) { isJumping = false; isMoving = false; if (currentSide == CurrentSide.LEFT) { currentSide = CurrentSide.RIGHT; } else if (currentSide == CurrentSide.RIGHT) { currentSide = CurrentSide.LEFT; } } if (other.gameObject.tag == "coin") { ScordeHandler.AddCoin(100); Destroy(other.gameObject); audioHandler.InstanceCoinSound(); } if (other.gameObject.tag == "falling_object") { Destroy(this.gameObject); gameManager.SetGameOver(); } if (other.gameObject.tag == "canon_ball") { Destroy(this.gameObject); gameManager.SetGameOver(); } if (other.gameObject.tag == "finish_level") { Destroy(this.gameObject); gameManager.SetSuccess(); } }
void Start() { elevatorHeight = (Screen.height / numberOfElevatorsPerLevel) / numberOfElevatorsPerLevel; currentSide = CurrentSide.right; ResetToLevelOne(); StartCoroutine(changeGreenLightIndex_Co()); SpawnNextLevel(); ChangeText(playerHealth); }
void ChangeSides() { if (currentSide == CurrentSide.left) { currentSide = CurrentSide.right; } else if (currentSide == CurrentSide.right) { currentSide = CurrentSide.left; } }
void MainActions(Actions action) { if (action == Actions.JumpLeft) { if (currentSide == CurrentSide.RIGHT) { currentSide = CurrentSide.LEFT; return; } else { isJumping = true; isMoving = false; Jump(); } } else if (action == Actions.JumpRight) { if (currentSide == CurrentSide.LEFT) { currentSide = CurrentSide.RIGHT; return; } else { isJumping = true; isMoving = false; Jump(); } } else if (action == Actions.GoUp) { this.GetComponent <Rigidbody2D> ().gravityScale = oldGravityScale; Vector2 currentVelocity = this.GetComponent <Rigidbody2D> ().velocity; currentVelocity.y = yVelocity; this.GetComponent <Rigidbody2D> ().velocity = currentVelocity; isMoving = true; } else if (action == Actions.GoDown) { this.GetComponent <Rigidbody2D> ().gravityScale = oldGravityScale; Vector2 currentVelocity = this.GetComponent <Rigidbody2D> ().velocity; currentVelocity.y = -yVelocity; this.GetComponent <Rigidbody2D> ().velocity = currentVelocity; isMoving = true; } }