void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Phobia")) { GameObject projectile = col.transform.parent.gameObject; foreach (string phobiaType in PhobiasList) { PhobiaAI phobiaAI = projectile.GetComponent <PhobiaAI>(); if (phobiaAI.CanKill(phobiaType)) { if (!hasAPlayerDie) { if (projectileThrower.playerNumber == 1) { ScoreManager.player2Score++; } else { ScoreManager.player1Score++; } projectileThrower.DropProjectile(); playerMovement.SetCurrentState(PlayerMovement.PlayerState.DIE); } hasAPlayerDie = true; } } } }
void VelocityUpdate(float horizontalDir) { string animState; switch (currentState) { case PlayerState.STAND: velocity = Vector2.zero; animState = isHolding ? "Idle_Holding" : "Idle"; anim.Play(animState); if (!onGround) { currentState = PlayerState.JUMP; break; } if (horizontalDir != 0) { currentState = PlayerState.WALK; break; } else if (Input.GetButton("Jump" + playerNumber)) { velocity.y = jumpSpeed; currentState = PlayerState.JUMP; break; } else if (Input.GetButton("Crouch" + playerNumber)) { velocity.x = 0; currentState = PlayerState.CROUCH; } break; case PlayerState.WALK: animState = isHolding ? "Walk_Holding" : "Walk"; anim.Play(animState); if (horizontalDir == 0) { currentState = PlayerState.STAND; velocity = Vector2.zero; break; } else { velocity.x = SetVelocityX(horizontalDir); } if (Input.GetButton("Jump" + playerNumber)) { velocity.y = jumpSpeed; //TODO Add audio(?) currentState = PlayerState.JUMP; break; } else if (!onGround) { currentState = PlayerState.JUMP; break; } else if (Input.GetButton("Crouch" + playerNumber)) { velocity.x = 0; currentState = PlayerState.CROUCH; } break; case PlayerState.JUMP: animState = isHolding ? "Jump_Holding" : "Jump"; anim.Play(animState); velocity.y -= gravityForce * Time.deltaTime; velocity.y = Mathf.Max(velocity.y, -maxFallSpeed); if (horizontalDir == 0) { velocity.x = 0; } else { velocity.x = SetVelocityX(horizontalDir); } if (!Input.GetButton("Jump" + playerNumber) && velocity.y > 0.0f) { velocity.y = Mathf.Min(velocity.y, minJumpForce); } if (onGround) { if (horizontalDir == 0) { currentState = PlayerState.STAND; velocity = Vector2.zero; } else { currentState = PlayerState.WALK; velocity.y = 0; } break; } break; case PlayerState.DIE: velocity = Vector2.zero; anim.Play("Die"); break; case PlayerState.DEAD: anim.Play("Dead"); if (!IsInvoking("nextScene")) { audioMngr.playRandomSound(); Invoke("nextScene", 1.75f); } break; case PlayerState.GRAB: anim.Play("Grab"); if (!onGround) { velocity.y -= gravityForce * Time.deltaTime; velocity.y = Mathf.Max(velocity.y, -maxFallSpeed); } break; case PlayerState.THROW: anim.Play("Throw"); if (!onGround) { velocity.y -= gravityForce * Time.deltaTime; velocity.y = Mathf.Max(velocity.y, -maxFallSpeed); } break; case PlayerState.CROUCH: anim.Play("Crouch"); projectileThrower.DropProjectile(); isHolding = false; if (!Input.GetButton("Crouch" + playerNumber)) { currentState = PlayerState.STAND; } break; } }