Пример #1
0
        // Interacts with other objects
        private void OnTriggerEnter2D(Collider2D collision)
        {
            // If we hit something that shares the same tag as the orig shooter, we ignore them
            // Think of this as friendly fire
            if (!collision.gameObject.CompareTag(origShooterTag))
            {
                // In general, we only go in here if this projectile can interact with it aka, if it is in the array
                if (CheckIfTagIsInArray(collision.gameObject.tag))
                {
                    switch (collision.gameObject.tag)
                    {
                    case "Enemy":
                        // Kills Enemy
                        projectileAnims.SetInteger("hit_type", 2);
                        GameManager.Instance.GetScoreSystem.IncrementScore(3);

                        EnemyMovement currEnemy = collision.gameObject.GetComponent <EnemyMovement>();
                        currEnemy.StartCoroutine(currEnemy.InvokeDefeated());
                        PlaySoundAtSource("Enemy");
                        break;

                    case "Player":
                        // If the game is in slow mo, the bullet does not do anything
                        if (SlowMoEffect.Instance.IsInSlowMo)
                        {
                            return;
                        }

                        // Else, we hurt player if they are not dodging
                        PlayerMovement playerMovement = collision.gameObject.GetComponent <PlayerMovement>();
                        if (playerMovement.GetPlayerMovementState != MovementState.DODGING)
                        {
                            // If the player is not invincible or in slow mo, they take damage
                            if (playerMovement.playerHealth.IsInvincible == false)
                            {
                                PlaySoundAtSource("Player");
                                playerMovement.playerHealth.CurrentHealth -= 1;
                            }
                            else
                            {
                                PlaySoundAtSource("Wall");
                            }
                        }
                        projectileAnims.SetInteger("hit_type", 2);
                        break;

                    case "Projectile":
                        // If the player shoot an enemy projectile, we add points as well as help refill the slowmo meter
                        if (origShooterTag == "Player" && collision.GetComponent <Projectile>().origShooterTag == "Enemy")
                        {
                            GameManager.Instance.GetScoreSystem.IncrementScore(1);
                            SlowMoEffect.Instance.AddAdditionalTime(10f);
                        }
                        PlaySoundAtSource("Projectile");
                        projectileAnims.SetInteger("hit_type", 2);
                        break;

                    case "Item":
                        // If the projectile hits an item, it will be destroyed
                        ItemBehavior currItem = collision.GetComponent <ItemBehavior>();

                        PlaySoundAtSource("Projectile");
                        projectileAnims.SetInteger("hit_type", 2);
                        currItem.StartCoroutine(currItem.InvokeDespawning(0f));
                        break;

                    case "Walls":
                        // All of these cases just cause the projectile to be destroyed (no special effects)
                        PlaySoundAtSource("Walls");
                        projectileAnims.SetInteger("hit_type", 1);
                        break;
                    }

                    // If for some reason it skipped the case, the projectile will default change to 2
                    if (projectileAnims.GetInteger("hit_type") == 0)
                    {
                        PlaySoundAtSource("Wall");
                        projectileAnims.SetInteger("hit_type", 2);
                    }
                    StartCoroutine(DestroyItself());
                }
            }
        }