Inheritance: MonoBehaviour
Beispiel #1
0
    public void OnExplode()
    {
        Destroy(gameObject);

        if (deathSound)
        {
            AudioSource.PlayClipAtPoint(deathSound, transform.position);
        }

        var t = transform;

        for (int i = 0; i < totalParts; i++)
        {
            t.TransformPoint(0, -100, 0);
            BodyPart clone = Instantiate(bodyPart, t.position, Quaternion.identity) as BodyPart;
            clone.rigidbody2D.AddForce(Vector3.right * Random.Range(-50, 50));
            clone.rigidbody2D.AddForce(Vector3.up * Random.Range(100, 400));
        }

        // click loads the scene that is current loaded using a class we already made
        GameObject      go     = new GameObject("ClickToContinue");
        ClickToContinue script = go.AddComponent <ClickToContinue> ();

        script.scene = Application.loadedLevelName;
        go.AddComponent <DisplayRestartText> ();
    }
Beispiel #2
0
    public void OnExplode()
    {
        //destroys player
        Destroy(gameObject);

        var t = transform;

        //creates body parts when player explodes
        for (int i = 0; i < totalBits; i++)
        {
            //parts start outside of the player's area
            t.TransformPoint(0, -100, 0);
            //clones the body parts (what gets cloned, position of clone, 0 rotation) as type Bodypart
            Bits clone = Instantiate(bits, t.position, Quaternion.identity) as Bits;
            //applies force to the objects in random direction left or right
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.right * Random.Range(-50, 50));
            //applies force to the object random intensity upward
            clone.GetComponent <Rigidbody2D>().AddForce(Vector3.up * Random.Range(100, 400));
        }

        GameObject      go     = new GameObject("ClickToContinue");
        ClickToContinue script = go.AddComponent <ClickToContinue> ();

        script.scene = Application.loadedLevelName;

        go.AddComponent <DisplayRestartText> ();
    }
Beispiel #3
0
    public void OnExplode()
    {
        Destroy(gameObject);
        var t = transform;

        for (int i = 0; i < totalParts; i++)
        {
            BodyPart clone = Instantiate(bodyPart, t.position, Quaternion.identity) as BodyPart;
            clone.rigidbody2D.AddForce(Vector3.right * (Random.Range(-50, 50)));
            clone.rigidbody2D.AddForce(Vector3.up * Random.Range(100, 400));
        }

        GameObject      go     = new GameObject("ClickToContinue");
        ClickToContinue script = go.AddComponent <ClickToContinue>();

        script.scene = Application.loadedLevelName;
        go.AddComponent <DisplayRestartText>();
    }
Beispiel #4
0
    void Update()
    {
        if (clickToContinue)
        {
            if (ctc == null)
            {
                if (anyKey)
                {
                    ctc = new ClickToContinue(gameScene);
                }
                else
                {
                    ctc = new ClickToContinue(gameScene, keyCode);
                }
            }

            ctc.CheckInput();
        }
    }
    public void OnExplode()
    {
        Destroy(gameObject);

        var currentTransform = transform;

        for (int i = 0; i < totalBodyParts; i++)
        {
            currentTransform.TransformPoint(0, -100, 0);
            BodyPart clone = Instantiate(bodyPart, currentTransform.position, Quaternion.identity) as BodyPart;

            clone.GetComponent <Rigidbody2D>().AddForce(Vector2.right * Random.Range(-50, 50));
            clone.GetComponent <Rigidbody2D>().AddForce(Vector2.up * Random.Range(100, 400));
        }

        GameObject      go     = new GameObject("ClickToContinue");
        ClickToContinue script = go.AddComponent <ClickToContinue>();

        script.sceneName = Application.loadedLevelName;
        go.AddComponent <DisplayRestartText>();
    }
    // onStateChange is called whenever we make a change to the player's state
    // from anywhere within the game's code.
    public void onStateChange(PlayerStateController.playerStates newState)
    {
        // If the current state and the new state are the same, abort - no need
        // to change to the state we're already in.
        if (newState == currentState)
        {
            return;
        }

        // Verify there are no special conditions that would cause this state to abort
        if (checkIfAbortOnStateCondition(newState))
        {
            return;
        }


        // Check if the current state is allowed to transition into this state. If it's not, abort.
        if (!checkForValidStatePair(newState))
        {
            return;
        }

        // Having reached here, we now know that this state change is allowed.
        // So let's perform the necessary actions depending on what the new state is.
        switch (newState)
        {
        case PlayerStateController.playerStates.idle:
            playerAnimator.SetInteger("StateAnim", 0);
            break;

        case PlayerStateController.playerStates.left:
            playerAnimator.SetInteger("StateAnim", 1);
            break;

        case PlayerStateController.playerStates.right:
            playerAnimator.SetInteger("StateAnim", 1);

            break;

        case PlayerStateController.playerStates.jump:
            if (playerHasLanded)
            {
                playerAnimator.SetInteger("StateAnim", 3);
                // Use the jumpDirection variable to specify if the player should be jumping left, right or vertical
                float jumpDirection = 0.0f;
                if (currentState == PlayerStateController.playerStates.left)
                {
                    jumpDirection = -1.0f;
                }
                else if (currentState == PlayerStateController.playerStates.right)
                {
                    jumpDirection = 1.0f;
                }
                else
                {
                    jumpDirection = 0.0f;
                }

                // Apply the actual jump force
                rigidbody2D.AddForce(new Vector2(jumpDirection * playerJumpForceHorizontal, playerJumpForceVertical));

                playerHasLanded = false;
                PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0f;
            }
            break;


        case PlayerStateController.playerStates.landing:
            playerHasLanded = true;
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = Time.time + 0.1f;
            break;

        case PlayerStateController.playerStates.falling:
            PlayerStateController.stateDelayTimer[(int)PlayerStateController.playerStates.jump] = 0.0f;
            break;

        case PlayerStateController.playerStates.kill:
            player_meter.updateDamage();
            break;

        case PlayerStateController.playerStates.resurrect:
            transform.position = playerRespawnPoint.transform.position;
            transform.rotation = Quaternion.identity;
            break;

        case PlayerStateController.playerStates.firingWeapon:
            playerAnimator.SetInteger("StateAnim", 2);
            break;

        case PlayerStateController.playerStates.attack:
            playerAnimator.SetInteger("StateAnim", 4);
            break;

        case PlayerStateController.playerStates.slide:
            playerAnimator.SetInteger("StateAnim", 5);

            // Apply the actual jump force
            //rigidbody2D.AddForce(new Vector2(110, playerJumpForceVertical));
            //transform.Translate(new Vector3(((playerWalkSpeed * 3) * -1.0f) * Time.deltaTime, 0.0f, 0.0f));
            //rigidbody2D.AddForce (new Vector2((2 * 90), 0));
            //VERIFICA O SCALE DA KUNEI BASEDO NO SCALE DO PERSONAGEM
            Vector3 localScale = transform.localScale;
            if (localScale.x < 0.0f)
            {
                rigidbody2D.AddForce(new Vector2((2 * -90), 0));
            }
            else
            {
                rigidbody2D.AddForce(new Vector2((2 * +90), 0));
            }
            break;

        case PlayerStateController.playerStates.takeDamage:

            if (PlayerStateController.playerStates.jump == currentState)
            {
                enemyAttackforce = 4;
            }
            else
            {
                enemyAttackforce = 2;
            }
            Vector3 localScale2 = transform.localScale;
            if (takeDamageWaitAnimation == true)
            {
                playerAnimator.SetInteger("StateAnim", 6);
                takeDamageWaitAnimation = false;
                if (enemieAttackDirection)
                {
                    rigidbody2D.AddForce(new Vector2((enemyAttackforce * -90), 180));
                }
                else
                {
                    rigidbody2D.AddForce(new Vector2((enemyAttackforce * +90), 180));
                }
            }
            player_meter.updateDamage();


            break;

        case PlayerStateController.playerStates.continueGame:


            Destroy(gameObject);
            GameObject      go     = new GameObject("ClickToContinue");
            ClickToContinue script = go.AddComponent <ClickToContinue> ();
            script.scene = Application.loadedLevelName;
            go.AddComponent <DisplayRestartText> ();

            break;
        }



        // Store the current state as the previous state
        previousState = currentState;

        // And finally, assign the new state to the player object
        currentState = newState;
    }