Пример #1
0
 private void Set_current_level()
 {
     if (number_of_level == 0)
     {
         ManagerKeeper.Set_current_level(0);
     }
     if (number_of_level == 1)
     {
         ManagerKeeper.Set_current_level(1);
     }
     if (number_of_level == 2)
     {
         ManagerKeeper.Set_current_level(2);
     }
     if (number_of_level == 3)
     {
         ManagerKeeper.Set_current_level(3);
     }
     if (number_of_level == 4)
     {
         ManagerKeeper.Set_current_level(4);
     }
     if (number_of_level == 5)
     {
         ManagerKeeper.Set_current_level(5);
     }
     //condition for the returning from other scenes when lose
     if (ManagerKeeper.Get_if_other_scene() == true && ManagerKeeper.Get_if_mini_game_completed() == false)
     {
         time_counter_script_inside = ManagerKeeper.Get_old_time_script_inside();
         special_computer_mini_game.gameObject.GetComponent <BoxCollider>().enabled = false;
         player.gameObject.GetComponent <Transform>().position = ManagerKeeper.Get_old_players_position();
         player.gameObject.GetComponent <CharController>().Set_lifes(ManagerKeeper.Get_old_number_of_lifes());
         player.gameObject.GetComponent <CharController>().Keep_respawn_point(ManagerKeeper.Get_old_respawn_point());
     }
     if (ManagerKeeper.Get_if_other_scene() == true && ManagerKeeper.Get_if_mini_game_completed() == true)//when winning
     {
         Debug.Log(ManagerKeeper.Get_respawn_point());
         time_counter_script_inside = ManagerKeeper.Get_old_time_script_inside();
         special_computer_mini_game.gameObject.GetComponent <BoxCollider>().enabled = false;
         player.gameObject.GetComponent <CharController>().Keep_respawn_point(ManagerKeeper.Get_old_respawn_point());
         ManagerKeeper.Set_if_mini_game_was_completed(false);
         ManagerKeeper.Is_in_other_scene(false);
         came_from_mini_game = true;
     }
     //else
     else if (ManagerKeeper.Get_if_other_scene() == false && ManagerKeeper.Get_if_mini_game_completed() == false)
     {
         time_counter_script_inside = time_counter;
     }
     if (came_from_mini_game == true)
     {
         if (ManagerKeeper.Get_respawn_point() == 0)
         {
             player.gameObject.GetComponent <Transform>().position = respawn_point[0].gameObject.GetComponent <Transform>().position;
         }
         if (ManagerKeeper.Get_respawn_point() == 1)
         {
             player.gameObject.GetComponent <Transform>().position = respawn_point[1].gameObject.GetComponent <Transform>().position;
         }
         if (ManagerKeeper.Get_respawn_point() == 2)
         {
             player.gameObject.GetComponent <Transform>().position = respawn_point[2].gameObject.GetComponent <Transform>().position;
         }
         if (ManagerKeeper.Get_respawn_point() == 3)
         {
             player.gameObject.GetComponent <Transform>().position = respawn_point[3].gameObject.GetComponent <Transform>().position;
         }
     }
 }
 void FixedUpdate()
 {
     if (enable_on_screen == true)
     {
         if (enemy_alive == true)
         {
             float distance = Vector3.Distance(transform.position, target.position);
             if (can_attack == true)
             {
                 if (distance < max_distance && this_object.position.x < player.gameObject.GetComponent <Transform>().position.x)
                 {
                     if (distance > min_distance)
                     {
                         play_attack_anim  = false;
                         play_idle_anim    = false;
                         play_running_anim = true;
                         Vector3 dirToTarget = transform.position - player.transform.position;
                         Vector3 newPos      = transform.position - dirToTarget;
                         rotation_sprite      = new Vector3(1, 1, 1);
                         transform.localScale = Vector3.SmoothDamp(transform.localScale, rotation_sprite, ref velocity, smoothTime, 10);
                         rb.MovePosition(Vector3.Lerp(transform.position, newPos, speed_when_spots_player * Time.fixedDeltaTime));
                         Light_slider(false);
                     }
                     if (distance < min_distance && player.gameObject.GetComponent <CharController>().Player_is_alive() == true)
                     {
                         play_attack_anim  = true;
                         play_idle_anim    = false;
                         play_running_anim = false;
                         Light_slider(true);
                         Increase_number_of_hits();
                     }
                     else if (distance < min_distance && player.gameObject.GetComponent <CharController>().Player_is_alive() == false)
                     {
                         play_attack_anim  = false;
                         play_idle_anim    = true;
                         play_running_anim = false;
                         Light_slider(false);
                     }
                 }
                 else if (distance < max_distance && this_object.position.x > player.gameObject.GetComponent <Transform>().position.x)
                 {
                     if (distance > min_distance)
                     {
                         play_attack_anim  = false;
                         play_idle_anim    = false;
                         play_running_anim = true;
                         Vector3 dirToTarget = transform.position - player.transform.position;
                         Vector3 newPos      = transform.position - dirToTarget;
                         rotation_sprite      = new Vector3(-1, 1, 1);
                         transform.localScale = Vector3.SmoothDamp(transform.localScale, rotation_sprite, ref velocity, smoothTime, 10);
                         rb.MovePosition(Vector3.Lerp(transform.position, newPos, speed_when_spots_player * Time.fixedDeltaTime));
                         Light_slider(false);
                     }
                     if (distance < min_distance && player.gameObject.GetComponent <CharController>().Player_is_alive() == true)
                     {
                         play_attack_anim  = true;
                         play_idle_anim    = false;
                         play_running_anim = false;
                         Light_slider(true);
                         Increase_number_of_hits();
                     }
                     else if (distance < min_distance && player.gameObject.GetComponent <CharController>().Player_is_alive() == false)
                     {
                         play_attack_anim  = false;
                         play_idle_anim    = true;
                         play_running_anim = false;
                         Light_slider(false);
                     }
                 }
                 else
                 {
                     delay_to_random_patrol += Time.fixedDeltaTime;
                     if (delay_to_random_patrol >= 3)
                     {
                         Generate_random_number();
                     }
                     if (random_to_patrol == 1)
                     {
                         if (quad.gameObject.GetComponent <Animator>().enabled == true)//newly added condition
                         {
                             play_attack_anim  = false;
                             play_idle_anim    = false;
                             play_running_anim = true;
                         }
                         if (direction == true)
                         {
                             rb.MovePosition(transform.position + translation * speed * Time.fixedDeltaTime);
                             rotation_sprite      = new Vector3(1, 1, 1);
                             transform.localScale = Vector3.SmoothDamp(transform.localScale, rotation_sprite, ref velocity, smoothTime, 10);
                         }
                         else
                         {
                             rb.MovePosition(transform.position + translation_to_left * speed * Time.fixedDeltaTime);
                             rotation_sprite      = new Vector3(-1, 1, 1);
                             transform.localScale = Vector3.SmoothDamp(transform.localScale, rotation_sprite, ref velocity, smoothTime, 10);
                         }
                     }
                     else
                     {
                         if (quad.gameObject.GetComponent <Animator>().enabled == true)//added condition
                         {
                             play_attack_anim  = false;
                             play_idle_anim    = true;
                             play_running_anim = false;
                         }
                     }
                 }
                 if (enemy_difficulty == 0)
                 {
                     if (numbers_of_hitted == 100 || numbers_of_hitted == 200 || numbers_of_hitted == 300 || numbers_of_hitted == 400 || numbers_of_hitted == 500)
                     {
                         player.gameObject.GetComponent <CharController>().Decrease_number_of_cells();
                         if (player.gameObject.GetComponent <CharController>().Return_number_of_cells() == 0)
                         {
                             Set_new_status();
                             Set_if_can_attack(false);
                         }
                         else
                         {
                             Set_if_can_attack(true);
                         }
                     }
                 }
                 if (enemy_difficulty == 1)
                 {
                     if (numbers_of_hitted == 5 || numbers_of_hitted == 10 || numbers_of_hitted == 15 || numbers_of_hitted == 20 || numbers_of_hitted == 25)
                     {
                         player.gameObject.GetComponent <CharController>().Decrease_number_of_cells();
                         if (player.gameObject.GetComponent <CharController>().Return_number_of_cells() == 0)
                         {
                             Set_new_status();
                             Set_if_can_attack(false);
                         }
                         else
                         {
                             Set_if_can_attack(true);
                         }
                     }
                 }
             }
             if (ManagerKeeper.Get_if_other_scene() == true)//to avoid enemy hit played when entering the minigame level03
             {
                 can_attack = false;
             }
             if (ManagerKeeper.Get_if_mini_game_completed() == true || ManagerKeeper.Get_if_mini_game_completed() == false)//to avoid enemy hit played when entering the minigame level03
             {
                 can_attack = true;
             }
             if (ManagerKeeper.Return_if_is_ed102_enteroing_some_place() == true)//to avoid enemies hit the player when entering some place
             {
                 can_attack = false;
             }
             if (ManagerKeeper.Return_if_is_ed102_enteroing_some_place() == false)
             {
                 can_attack = true;
             }
         }
         if (enemy_alive == false)
         {
             delay_for_dead   += Time.fixedDeltaTime;
             play_attack_anim  = false;
             play_idle_anim    = false;
             play_running_anim = false;
             play_die_anim     = true;
             if (delay_for_dead >= 1.5f)
             {
                 Destroy(gameObject);
                 delay_for_dead = 0;
             }
         }
     }
 }