Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (rightPadPressed && !right.padPressed)
        {
            rightPadPressed = false;
        }

        if (sugarRush)
        {
            sugarCD -= Time.deltaTime;
            sugar.SetTime(sugarCD);

            if (sugarCD <= 0)
            {
                sugar.gameObject.SetActive(false);
                sugarRush = false;
            }
        }

        if (slimed)
        {
            slimeCounter += Time.deltaTime;
            slimedDisplay.SetActive(true);
        }

        if (slimeCounter >= 5)
        {
            slimeCounter = 0;
            slimed       = false;
            slimedDisplay.SetActive(false);
        }

        if (isFlying)
        {
            flyTimer += Time.deltaTime;
        }
        if (flyTimer >= flyLimit)
        {
            isFlying      = false;
            rb.useGravity = true;
        }

        if (right.padPressed && !rightPadPressed)
        {
            rightPadPressed = true;

            if (isGrounded)
            {
                rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            }
            else if (flyTimer < flyLimit)
            {
                isFlying      = true;
                rb.useGravity = false;

                Vector3 vel = rb.velocity;
                vel.y       = 0;
                rb.velocity = vel;
            }
        }

        if (left.gripped && !hook.IsActive())
        {
            hook.SetActive(true);
        }
        else if (!left.gripped && hook.IsActive())
        {
            hook.SetActive(false);
        }

        if (left.triggerPressed)
        {
            if (right.triggerPressed && !sugarRush)
            {
                GameObject[] fruits = GameObject.FindGameObjectsWithTag("Fruit");

                foreach (GameObject fruit in fruits)
                {
                    fruit.GetComponent <EnemyMovement>().Moldy();
                    FNShootProjectile sp = fruit.GetComponent <FNShootProjectile>();

                    if (sp != null)
                    {
                        sp.Moldy();
                    }

                    sugar.gameObject.SetActive(true);
                    sugarRush = true;
                    sugarCD   = 5f;
                }
            }
            else if (left.gripped)
            {
                hook.Fire();
            }
            else if (shurikenCount > 0)
            {
                shurikenPreview.SetActive(true);
            }
        }
        else
        {
            if (shurikenPreview.activeInHierarchy)
            {
                shurikenPreview.SetActive(false);
                GameObject.Instantiate(shuriken, left.gameObject.transform.position, left.gameObject.transform.rotation);
                shurikenCount--;
                shurikenCounter.text = "Shurikens: " + shurikenCount;
            }
        }

        if (left.padPressed)
        {
            if (isFlying)
            {
                Vector3 pos   = transform.position;
                Vector3 delta = head.transform.forward;

                pos += delta * flySpeed * Time.deltaTime;

                transform.position = pos;
            }
            else
            {
                Vector3 pos   = transform.position;
                Vector3 delta = head.transform.forward;

                delta.y = 0;
                pos    += delta * walkSpeed * Time.deltaTime;

                transform.position = pos;
            }
        }
    }