// Use this for initialization void Start() { Vector3 vel = gameObject.GetComponent <Rigidbody2D>().velocity; vel.x = VariableSpeed.current; gameObject.GetComponent <Rigidbody2D>().velocity = vel; jumpDelay = true; playerSprite = gameObject.GetComponentInChildren <SpriteRenderer>(); playerSprite.color = playerColour; playerSprite.sortingOrder = Random.Range(0, 10); powerUps.createPowerupEffect(); animationBoard.FlappyMode = false; animationBoard.IntroMode = false; switch (LevelTypeManager.currentLevel) { case LevelTypeManager.Level.lowGravity: gameObject.GetComponent <Rigidbody2D>().gravityScale = lowGravityScale; jumpVel = lowGravityJumpVel; break; case LevelTypeManager.Level.flappyBird: gameObject.GetComponent <Rigidbody2D>().gravityScale = flappyGravityScale; animationBoard.FlappyMode = true; jumpTimeDelay = flappyJumpTimeDelay; jumpVel = flappyJumpVel; break; case LevelTypeManager.Level.gravityFlip: gameObject.GetComponent <Rigidbody2D>().gravityScale = flipGravityScale; animationBoard.FlappyMode = false; jumpVel = gravFlipJumpVel; break; default: gameObject.GetComponent <Rigidbody2D>().gravityScale = gravityScale; break; } animationBoard.Fall(); }
//} void FixedUpdate() { //Debug.Log(animator.GetCurrentAnimatorStateInfo(0).IsName("idle")); if (!animator.GetCurrentAnimatorStateInfo(0).IsName("intro")) { Vector2 position = (Vector2)gameObject.transform.position; float raycastLength = 0.5f; Vector2 down = -Vector2.up * raycastLength; bool onTheGround = Physics2D.Raycast(position, down, raycastLength, ~mask.value); Debug.DrawRay(position, down, Color.red, raycastLength); vel += Physics2D.gravity * gravScale * Time.deltaTime; if (onTheGround) { if (!onTheGroundLast) { animation.Land(); calledFalling = false; } vel = new Vector2(0, 0); if (Input.GetKey(mPKey) && canJump) { vel = new Vector2(0, jumpVel); animation.Jump(); calledFalling = false; canJump = false; //PowerupSounds.inst.playDoubleJump(); SoundManager.instance.playMenuJump(transform.position); Invoke("setCanJump", jumpDelay); } } else { if (!calledFalling && vel.y < 0) { animation.Fall(); calledFalling = true; } } gameObject.transform.position = position + vel * Time.deltaTime; if (gameObject.transform.position.y < 1) { gameObject.transform.position = new Vector2(gameObject.transform.position.x, 1); } onTheGroundLast = onTheGround; } }