Пример #1
0
    public IEnumerator RespawnPlayerCo()
    {
        Instantiate(deathParticle, CharacterRobotBoy.transform.position, CharacterRobotBoy.transform.rotation);
        CharacterRobotBoy.enabled = false;
        CharacterRobotBoy.GetComponent <Renderer>().enabled = false;
        Debug.Log("Player Respawn");
        yield return(new WaitForSeconds(respawnDelay));

        CharacterRobotBoy.transform.position = currentCheckpoint.transform.position;
        CharacterRobotBoy.enabled            = true;
        CharacterRobotBoy.GetComponent <Renderer>().enabled = true;
        healthManager.isDead = false;
        healthManager.FullHealth();
        Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
    }
Пример #2
0
    // Coroutine that handles the end of the game
    public IEnumerator EndGameCo()
    {
        // Update highscore
        scoreManager.increaseScore = false;
        scoreManager.UpdateHighScore();

        // Disable players
        Player1.enabled = false;
        Player2.enabled = false;
        Player1.GetComponent <MagicUser> ().enabled        = false;
        Player2.GetComponent <MagicUser> ().enabled        = false;
        Player1.GetComponent <Rigidbody2D> ().velocity     = Vector2.zero;
        Player2.GetComponent <Rigidbody2D> ().velocity     = Vector2.zero;
        Player1.GetComponent <Rigidbody2D> ().gravityScale = 0.0f;
        Player2.GetComponent <Rigidbody2D> ().gravityScale = 0.0f;

        yield return(new WaitForSeconds(1.0f));

        scoreDeathPanel.SetActive(true);
    }
    // Update is called once per frame
    void Update()
    {
        if (timeLeftBeforeReset > 0)
        {
            timeLeftBeforeReset -= Time.deltaTime;
        }

        if (timeLeftBeforeReset < 0)
        {
            timeLeftBeforeReset = 0;
        }

        if (timeLeftBeforeReset != 0)
        {
            return;
        }

        var button = Input.GetButton(buttonName);

        var doNotCare  = !oldButtonState && !button;
        var isHold     = oldButtonState && button;
        var isReleased = oldButtonState && !button;
        var isPressed  = !oldButtonState && button;

        oldButtonState = button;

        if (doNotCare)
        {
            return;
        }

        if (isPressed)
        {
            caster.DisableMovement();

            shadowBox = Instantiate(boxModel) as GameObject;
            shadowBox.transform.SetParent(this.transform);
            shadowBox.GetComponent <SpriteRenderer>().color    = new Color(0f, 0.5f, 0f, 0.5f);
            shadowBox.GetComponent <Rigidbody2D>().isKinematic = true;

            // TODO: Disable collisions!

            var position = new Vector3(0f, 0f, 0f);

            var facingRight = caster.GetComponent <PlatformerCharacter2D>().FacingRight();

            if (facingRight)
            {
                position.x = 1f;
            }
            else
            {
                position.x = 2f;
            }

            Debug.Log(position);

            shadowBox.transform.localPosition = position;

            // TODO: Transfer movement to box
        }
        else if (isReleased)
        {
            Reset();
        }
        else if (isHold)
        {
            var validation = Input.GetButton(validationButtonName);

            if (!validation)
            {
                return;
            }

            if (persistenBox)
            {
                Destroy(persistenBox);
            }

            persistenBox = Instantiate(boxModel,
                                       shadowBox.transform.position,
                                       Quaternion.identity) as GameObject;

            Reset();

            timeLeftBeforeReset = cooldown;
        }
    }