Advertisement
kadyr

Untitled

Sep 5th, 2021
1,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Switch : MonoBehaviour
  7. {
  8.     public GameObject riffle;
  9.     public GameObject shotgun;
  10.     public GameObject pistol;
  11.    
  12.     int level = 1;
  13.  
  14.     void Start()
  15.     {
  16.         switch (level)
  17.         {
  18.             case 1:
  19.                 ChooseWeapon("Пистолет");
  20.                 break;
  21.             case 2:
  22.                 ChooseWeapon("Дробовик");
  23.                 break;
  24.             case 3:
  25.                 ChooseWeapon("Автомат");
  26.                 break;
  27.             default:
  28.                 print("Для этого уровня не подготовлено оружие");
  29.                 break;
  30.         }
  31.     }
  32.  
  33.     private void Update()
  34.     {
  35.         if(Input.GetKeyDown(KeyCode.Alpha1))
  36.             ChooseWeapon("Пистолет");
  37.         if(Input.GetKeyDown(KeyCode.Alpha2))
  38.             ChooseWeapon("Дробовик");
  39.     }
  40.  
  41.     private void ChooseWeapon(string weaponName)
  42.     {
  43.         switch (weaponName)
  44.         {
  45.             case "Пистолет":
  46.                 riffle.SetActive(false);
  47.                 shotgun.SetActive(false);
  48.                 pistol.SetActive(true);
  49.                 break;
  50.             case "Дробовик":
  51.                 riffle.SetActive(false);
  52.                 shotgun.SetActive(true);
  53.                 pistol.SetActive(false);
  54.                 break;
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement