コード例 #1
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.CompareTag("Player"))
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Debug.Log("Gotcha");
             if (energy.GetEnergy() < 100f)
             {
                 Meditate();
             }
         }
     }
 }
コード例 #2
0
    // 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);
            }
        }
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    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);
            }
        }
    }