コード例 #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            PlayerPlatformer playerscript = collision.gameObject.GetComponent <PlayerPlatformer>();

            if (!playerscript.isBurning)
            {
                collision.gameObject.GetComponent <Rigidbody2D>().velocity = Vector2.up * rebound;
                playerscript.isBurning = true;
                playerscript.animator.SetBool("IsBurning", true);
                playerscript.StartCoroutine("ResetAddforce");
            }
            else
            {
                Destroy(collision.transform.GetChild(0).gameObject);
                collision.gameObject.GetComponent <Animator>().SetTrigger("FireDeath");
            }
        }
    }
コード例 #2
0
    private void ShieldBash()
    {
        player.animator.SetTrigger("PlayerBash");
        if (hitting)
        {
            hitting = false;
            switch (shieldMovScript.shieldDirection)
            {
            case ShieldMovement.Directions.N:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(0, -1) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.NE:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(-1, -1) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.E:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(-1, 0) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.SE:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(-1, 1) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.S:
                playerRb2d.velocity           = Vector2.up * bashForce * 2;
                playerRb2d.transform.rotation = new Quaternion(0, 0, 90, 0);
                //playerRb2d.velocity = Vector2.zero;
                //playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                //playerRb2d.AddForce(new Vector2(0, 1) * bashForce, ForceMode2D.Impulse);
                //playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.SW:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(1, 1) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.W:
                playerRb2d.velocity = Vector2.right * bashForce;
                //playerRb2d.velocity = Vector2.zero;
                //playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                //playerRb2d.AddForce(new Vector2(1, 0) * bashForce, ForceMode2D.Impulse);
                //playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            case ShieldMovement.Directions.NW:
                playerRb2d.velocity = Vector2.zero;
                playerRb2d.bodyType = RigidbodyType2D.Dynamic;
                playerRb2d.AddForce(new Vector2(1, -1) * bashForce, ForceMode2D.Impulse);
                playerRb2d.bodyType = RigidbodyType2D.Kinematic;
                player.StartCoroutine("ResetAddforce");
                Destroy(toDestroy);
                break;

            default:
                break;
            }
        }
    }