/* * * Public functions * */ public void TakeDamage(int damage) { int current = playerHealth.curHealth; Debug.Log(current); playerHealth.AdjustCurrentHealth(-damage); current -= damage; if (current >= 30 && burnParticles.isPlaying) { // playerHealth.curHealth = current; burnParticles.Stop(); } if (current <= 20 && !burnParticles.isPlaying) { //playerHealth.curHealth = current; burnParticles.Play(); } if (playerHealth.curHealth == 0 && !GameManagerSnow.isGamePaused()) { //GameOver animator.SetBool("isMoving", false); animator.SetBool("isKilled", true); explodeParticles.Play(); gameManager.FinishGame(SecondPlayer); soundManager.PlayDeath(); } else { soundManager.PlayHurt(); } }
void FixedUpdate() { if (GameManagerSnow.isGamePaused()) { return; } float vertical = Input.GetAxisRaw(vAxisName); float horizontal = Input.GetAxisRaw(hAxisName); float shoot = Input.GetAxisRaw(attackAxisName); Vector2 localUp = new Vector2(transform.up.x, transform.up.y); if (vertical != 0) { Vector2 engineForce = Vector2.Lerp(Vector2.zero, localUp * vertical * MaximalSpeed, Velocity * Time.deltaTime); rb.AddForce(engineForce); soundManager.PlayRide(); animator.SetBool("isMoving", true); } else { animator.SetBool("isMoving", false); } SetupParticles(vertical); Vector2 velocityVector = rb.velocity.normalized; float dot = Vector2.Dot(velocityVector, localUp); if (horizontal != 0) { if (dot < 0 && rb.velocity.magnitude > 0 && vertical < 0) { rb.MoveRotation(rb.rotation + RotationSpeed * horizontal); } else { rb.MoveRotation(rb.rotation - RotationSpeed * horizontal); } } if ((dot != 1) && (dot != -1) && (velocityVector.magnitude != 0)) { rb.velocity = Vector2.Lerp(rb.velocity, localUp * dot * rb.velocity.magnitude, FrictionScale * Time.deltaTime); } if (shoot != 0 && timer >= ReloadSpeed) { Shoot(localUp); } timer += Time.deltaTime; }