// Update is called once per frame void FixedUpdate() { if (m_jumping) { energyController.ChangeEnergy(-jetPackEnergyCost); if (rb.velocity.y < maxSpeed) { rb.AddForce(new Vector2(0f, jetPackStrength)); } ; if (!isFlying) { jetPackParticles.Play(true); //JetPackSound (true); isFlying = true; } ; } else { jetPackParticles.Stop(true); isFlying = false; //JetPackSound (false); }; }
// Update is called once per frame void Update() { // Handles mouse movement and crosshair movement mousePosition = cameraObj.ScreenToWorldPoint(Input.mousePosition); mouseRotation = (Mathf.Atan2(mousePosition.x - this.transform.position.x, mousePosition.y - this.transform.position.y) * Mathf.Rad2Deg - 90f) * -1f; if (mouseRotation < 0f) { mouseRotation += 360f; } // Normalize the mouse movement to the position the player is facing if (playerWalk.GetRight()) { // If the player is facing right if ((mouseRotation > 90f) && (mouseRotation <= 180f)) { mouseRotation = 180f - mouseRotation; } else if ((mouseRotation > 180f) && (mouseRotation < 270f)) { mouseRotation = -mouseRotation + 180f; } aimIndicator.transform.localScale = new Vector3(1f, 1f, 1f); } else { // If the player is facing left if (mouseRotation > 270f) { mouseRotation = -mouseRotation + 180f; } else if (mouseRotation < 90f) { mouseRotation = 180f - mouseRotation; } aimIndicator.transform.localScale = new Vector3(1f, -1f, 1f); } // crosshairBody.MovePosition(mousePosition); aimIndicator.transform.rotation = Quaternion.Euler(0f, 0f, mouseRotation); // Handles the firing routine (with energy) if (Input.GetButtonDown("Fire1") && canFire) { if (energy.GetEnergy() >= 10f) { sounds.StartSom(3); weapon.Fire(mouseRotation); energy.ChangeEnergy(-10f); } } }
IEnumerator HealEnergy() { InputStatus(false); playerBody.velocity = Vector2.zero; while (energy.GetEnergy() < 100f) { yield return(new WaitForSeconds(0.01f)); sounds.StartSom(0); energy.ChangeEnergy(1f); } InputStatus(true); }
private void FixedUpdate() { // Read the inputs. float h = 0; //From touch-screen if (Input.touchSupported && Input.touchCount > 0) { Touch currentTouch = Input.touches[0]; if (currentTouch.phase == TouchPhase.Began) { touchPivot = currentTouch.position; } if (Input.touches[0].phase == TouchPhase.Moved || Input.touches[0].phase == TouchPhase.Stationary) { Vector2 delta = (currentTouch.position - touchPivot).normalized; h = delta.x; } } else //From keyboard { h = Input.GetAxis("Horizontal"); } // Pass all parameters to the character control script. m_Character.Move(h, false, m_Jump); if (m_Jump) { energyController.ChangeEnergy(jumpCost); } m_Jump = false; energyController.ChangeEnergy((Mathf.Abs(h) * -1f) * moveMultiplier); soundController.SetValue(m_Character.m_Rigidbody2D.velocity.magnitude); }
IEnumerator HealEnergy() { playerInput.SetHealing(true); playerBody.gravityScale = 0f; playerBody.velocity = Vector2.zero; while (energy.GetEnergy() < 100f) { Debug.Log(energy.GetEnergy()); yield return(new WaitForSeconds(0.5f)); audioManager.PlaySound("RestoreMana"); energy.ChangeEnergy(25f); } playerBody.gravityScale = 4f; playerInput.SetHealing(false); }
private void Update() { // Prevent from moving if player is healing if (!isHealing) { // Handles horizontal input horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; anim.SetFloat("speed", Mathf.Abs(horizontalMove)); // Handles jump input if (Input.GetButtonDown("Jump")) { isJumping = true; audioManager.PlaySound("Jump"); } // Handles mouse movement and crosshair movement mousePosition = cameraObj.ScreenToWorldPoint(Input.mousePosition); mouseRotation = (Mathf.Atan2(mousePosition.x - this.transform.position.x, mousePosition.y - this.transform.position.y) * Mathf.Rad2Deg - 90f) * -1f; if (mouseRotation < 0f) { mouseRotation += 360f; } // Normalize the mouse movement to the position the player is facing if (this.transform.localScale.x > 0f) { // If the player is facing right if ((mouseRotation > 90f) && (mouseRotation <= 180f)) { mouseRotation = 180f - mouseRotation; } else if ((mouseRotation > 180f) && (mouseRotation < 270f)) { mouseRotation = -mouseRotation + 180f; } aimIndicator.transform.localScale = new Vector3(1f, 1f, 1f); } else { // If the player is facing left if (mouseRotation > 270f) { mouseRotation = -mouseRotation + 180f; } else if (mouseRotation < 90f) { mouseRotation = 180f - mouseRotation; } aimIndicator.transform.localScale = new Vector3(1f, -1f, 1f); } crosshairBody.MovePosition(mousePosition); aimIndicator.transform.rotation = Quaternion.Euler(0f, 0f, mouseRotation); // Handles the firing routine if ((energy.GetEnergy() >= 10f) && (Input.GetButtonDown("Fire1"))) { weapon.Fire(mouseRotation); audioManager.PlaySound("EnemySuperBolt"); energy.ChangeEnergy(-10f); } } }