public void Move(float move, bool jump)
    {
        //only control the player if grounded or airControl is turned on
        float moveAbs = Mathf.Abs(move);

        if (IsGrounded || airControl)
        {
            // The Speed animator parameter is set to the absolute value of the horizontal input.
            anim.SetFloat("Speed", moveAbs);

            // Move the character
            GetComponent <Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent <Rigidbody2D>().velocity.y);

            // If the input is moving the player right and the player is facing left...
            if (move > 0 && !facingRight)
            {
                // ... flip the player.
                Flip();
            }
            // Otherwise if the input is moving the player left and the player is facing right...
            else if (move < 0 && facingRight)
            {
                // ... flip the player.
                Flip();
            }
        }

        // If the player should jump...
        if (IsGrounded == true)
        {
            if (jump == true)
            {
                // Add a vertical force to the player.
                anim.SetBool("Ground", false);
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpForce));

                // Play the jump sound
                jumpAudio.Play();
                jumpParticles.Stop();
                jumpParticles.Play();

                // Stop the running audio
                runningAudio.Stop();
            }
            else if ((moveAbs > 0.1f) && (runningAudio.Audio.isPlaying == false))
            {
                runningAudio.Play();
            }
            else if ((moveAbs < 0.1f) && (runningAudio.Audio.isPlaying == true))
            {
                runningAudio.Stop();
            }
        }
        else if (runningAudio.Audio.isPlaying == true)
        {
            // Stop the running audio
            runningAudio.Stop();
        }
    }
    void Finish(bool complete)
    {
        if (complete == true)
        {
            completeMenu.Show();
            enemyNumbersLabel.text = "0";
            targetReticle.SetActive(false);

            // Unlock the next level
            GameSettings settings = Singleton.Get <GameSettings>();
            if ((Application.loadedLevel >= settings.NumLevelsUnlocked) && (Application.loadedLevel < settings.CreditsLevel.Ordinal))
            {
                settings.NumLevelsUnlocked = Mathf.Clamp((Application.loadedLevel + 1), 1, settings.NumLevels);
            }

            // Play sound
            successSound.Play();
        }
        else
        {
            deadMenu.Show();

            // Play sound
            failSound.Play();
        }

        pauseStartedRealTime = -1f;

        jetSound.Stop();
        enabled        = false;
        Time.timeScale = 0.1f;
    }
Exemple #3
0
    IEnumerator Die()
    {
        yield return(new WaitForSeconds(dieAfter));

        soundCache.Stop();
        foreach (ParticleSystem system in particlesCache)
        {
            system.Stop();
        }
        gameObject.SetActive(false);
    }
    // Update is called once per frame
    protected void Update()
    {
        if (beam.IsShooting == true)
        {
            // Check if we're done
            if ((Time.time - lastShot) > fireDuration)
            {
                beam.IsShooting = false;
                lastShot        = Time.time;
                audio.Stop();
            }
        }
        else if ((Time.time - lastShot) > shootEvery)
        {
            lastShot        = Time.time;
            beam.IsShooting = true;
            audio.Play();
        }

        lookRotation       = Quaternion.LookRotation(ShipControl.TransformInfo.position - transform.position);
        body.rotation      = Quaternion.Slerp(body.rotation, lookRotation, (Time.deltaTime * rotateLerp));
        beam.Body.rotation = body.rotation;
    }