// Update is called once per frame void Update() { ControllerDriver controllerScriptObm = playerObm.GetComponent <ControllerDriver>(); if (controllerScriptObm.controllerEnabledObm == true) { controllerAttackObm(); } else { //Check if cooldown timer is 0 and if the energy bar isn't empty also if the pausemenu is false if (timerObm <= 0 && GameObject.Find("Energy bar").GetComponent <Slider>().value > 0) { //Fire1 is the input to attack (Leftmouse button) if (Input.GetButtonDown("Fire1")) { //Checks how many enemies were hit Collider2D[] enemiesToDamageObm = Physics2D.OverlapCircleAll(attackPosObm.position, attackRangeObm, whatIsEnemiesObm); for (int i = 0; i < enemiesToDamageObm.Length; i++) { //Enemy takes damage enemiesToDamageObm[i].GetComponent <EnemyController>().TakeDamageObm(damageObm); Debug.Log("HIT"); } AttackAnimObm(); timerObm = timeBetweenAttackObm; FindObjectOfType <PlayerHud>().UseEnergyObm(20); } } timerObm -= Time.deltaTime; } }
private void JumpObm() { ControllerDriver controllerScriptObm = playerObm.GetComponent <ControllerDriver>(); if (controllerScriptObm.controllerEnabledObm == true) { if (isGroundedObm == true && controllerScriptObm.jumpInputObm == true) { //Player jumps. Gains extra height with Addforce isGroundedObm = false; playerRigidbodyObm.AddForce(new Vector2(0f, jumpSpeedObm)); jumpSoundObm.Play(); controllerScriptObm.jumpInputObm = false; } else if (isGroundedObm == false) { playerRigidbodyObm.AddForce(new Vector2(0f, 0)); } } else { if (isGroundedObm == true && Input.GetButtonDown("Jump")) { isGroundedObm = false; playerRigidbodyObm.AddForce(new Vector2(0f, jumpSpeedObm)); jumpSoundObm.Play(); } } }
//Same as the function before but checks for controller input public void controllerAttackObm() { ControllerDriver controllerScriptObm = playerObm.GetComponent <ControllerDriver>(); if (controllerScriptObm.attackInputObm == true) { if (timerObm <= 0 && GameObject.Find("Energy bar").GetComponent <Slider>().value > 0) { Collider2D[] enemiesToDamageObm = Physics2D.OverlapCircleAll(attackPosObm.position, attackRangeObm, whatIsEnemiesObm); for (int i = 0; i < enemiesToDamageObm.Length; i++) { enemiesToDamageObm[i].GetComponent <EnemyController>().TakeDamageObm(damageObm); Debug.Log("HIT"); } AttackAnimObm(); timerObm = timeBetweenAttackObm; FindObjectOfType <PlayerHud>().UseEnergyObm(20); controllerScriptObm.attackInputObm = false; } timerObm -= Time.deltaTime; } }
private void MoveObm() { //Checks for controller ControllerDriver controllerScriptObm = playerObm.GetComponent <ControllerDriver>(); // MOVE if (controllerScriptObm.controllerEnabledObm == false) { //Calculates the input given to walk xInputObm = Input.GetAxisRaw("Horizontal") * runSpeedObm * Time.fixedDeltaTime; } else { if (controllerScriptObm.controllerInputObm == "1" || controllerScriptObm.controllerInputObm == "-1") { int inputIntegerObm = Convert.ToInt32(controllerScriptObm.controllerInputObm); float inputFloatObm = (float)inputIntegerObm; xInputObm = inputFloatObm * runSpeedObm * Time.fixedDeltaTime; } else { xInputObm = 0f; } } //this is for the basic inputs with WASD Vector3 targetVelocityObm = new Vector2(xInputObm * 10f, playerRigidbodyObm.velocity.y); playerRigidbodyObm.velocity = Vector3.SmoothDamp(playerRigidbodyObm.velocity, targetVelocityObm, ref VelocityObm, movementSmoothingObm); // JUMP CALCULATION if (controllerScriptObm.controllerEnabledObm == true) { //checks if object hit the ground. isGroundedObm = Physics2D.OverlapCircle(groundCheckObm.position, checkRadiusObm, whatIsGroundObm); //checks if the jump button is pressed and if not, the object needs to fall down quicker. if (playerRigidbodyObm.velocity.y < 0) { playerRigidbodyObm.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplierObm - 1) * Time.fixedDeltaTime; } else if (playerRigidbodyObm.velocity.y > 0 && controllerScriptObm.jumpInputObm == false) { playerRigidbodyObm.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplierObm - 1) * Time.fixedDeltaTime; } } //Mouse & Keyboard else { isGroundedObm = Physics2D.OverlapCircle(groundCheckObm.position, checkRadiusObm, whatIsGroundObm); if (playerRigidbodyObm.velocity.y < 0) { playerRigidbodyObm.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplierObm - 1) * Time.fixedDeltaTime; } else if (playerRigidbodyObm.velocity.y > 0 && !Input.GetButton("Jump")) { playerRigidbodyObm.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplierObm - 1) * Time.fixedDeltaTime; } } // FLIP Character left or right if (xInputObm < 0f && facingrightObm == true) { flipObm(); } else if (xInputObm > 0f && facingrightObm == false) { flipObm(); } }