Example #1
0
    void KillCharacter()
    {
        if (check_player)
        {
            // delete all enemeies because the player died
            GameObject[] game_object_list = GameObject.FindGameObjectsWithTag("Enemy");
            for (int ii = 0; ii < game_object_list.Length; ii++)
            {
                game_object_list[ii].GetComponent <EnemyContoller>().enabled = false;
            }
            // call enemy manager to stop spawning enemis
            ZombieSpawner.zombie_spawner.StopSpawning();

            GetComponent <PlayerMoveAction>().enabled     = false;
            GetComponent <FireBulletController>().enabled = false;
            GetComponent <WeaponController>().getter_user_weapon().gameObject.SetActive(false);

            // Making the player fall down.
            GameObject player_object = GameObject.Find("Player");
            player_object.transform.position -= player_object.transform.up * Time.deltaTime;
        }
        if (check_zombie)
        {
            // GetComponent<Animator>().enabled = false;
            // GetComponent<BoxCollider>().isTrigger = false;
            // enemy_animation_controller.DeadMotion();
            // GetComponent<Rigidbody>().AddTorque(-transform.forward * 5f);//check if this is needed after testing
            // enemy_controller.enabled = false;
            // nav_mesh_agent.enabled = false;
            // enemy_animation_controller.enabled = false;


            // StartCoroutine(DeadSound());
            // EnemyManager spawn more enemies
            // EnemyManager.instance.EnemyDied(true);

            // Better use this since zombie has dead animation
            nav_mesh_agent.velocity  = Vector3.zero;
            nav_mesh_agent.isStopped = true;
            enemy_controller.enabled = false;
            enemy_animation_controller.DeadMotion();

            StartCoroutine(Dying_Sound_Trigger());

            // Notifying ZombieSpawner to spawn more enemies
            ZombieSpawner.zombie_spawner.Zombie_is_Dead();// This may be the code that respawns the zomibe automatcally.
        }

        // used to stop or restart the game
        if (tag == "Player")
        {
            Invoke("Reset_Game", 3f);
        }
        else
        {
            Invoke("Turn_Off_Game", 3f);
        }
    }