Пример #1
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag.Equals("Player"))
        {
            if (collision.contacts.Length > 0)
            {
                ContactPoint contact = collision.contacts[0];
                if (Vector3.Dot(contact.normal, Vector3.down) > 0.5f)
                {
                    //Grabs the player jumping script from the player the enemy made collision with
                    PlayerJumping jump = collision.gameObject.GetComponent <PlayerJumping>();
                    //Makes the player jump up
                    jump.Jump(5f);
                    soundPlayer.PlaySound(Sounds.KICKING);
                    if (!stompedHead)
                    {
                        stompedHead = true;
                        gameManager.IncreaseScore(score);

                        //Checks if the enemy has to been deleted from the scene
                        if (enemy.deleted)
                        {
                            gameObject.SetActive(false);                //Destroy(gameObject);
                        }
                        //Pauses the movement of the enemy
                        else
                        {
                            pauseMovement = true;
                        }
                    }
                    else
                    {
                        kickedEnemy = true;
                    }
                }
                //Checks if the player hits the enemy while its not moving anymore
                else if (stompedHead && pauseMovement)
                {
                    //Grabs the new direction of the enemy
                    direction   = (int)Input.GetAxisRaw("Horizontal");
                    kickedEnemy = true;
                    soundPlayer.PlaySound(Sounds.KICKING);
                }
                else
                {
                    gameManager.HandleDeath();
                }
            }
        }
        else if (collision.gameObject.tag.Equals("Floor") || collision.gameObject.tag.Equals("Interactable"))
        {
            //Switch direction
            direction = direction == 1 ? -1 : 1;
            //Checks if the enemy hit a interactable and is in shell form (aka been stomped and moving)
            if (collision.gameObject.tag.Equals("Interactable") && stompedHead)
            {
                BlockHandler blockHandler = collision.gameObject.GetComponent <BlockHandler>();
                blockHandler.HandleCollision();
            }
        }
    }