private void OnTriggerEnter2D(Collider2D collision) { string tag = collision.gameObject.tag; TypeWeapon typePickupWeapon = TranslateTag(tag); Weapon pickupWeapon = collision.gameObject.GetComponent <Weapon>(); if (inventory.IsTaken(typePickupWeapon)) { bool canPickup = inventory.CanPickupAmmuntion(typePickupWeapon); if (canPickup) { inventory.PickupAmmunition(pickupWeapon, typePickupWeapon); audioSource.PlayOneShot(pickupWeapon.pickupSound, this.soundVolume); Destroy(collision.gameObject); } } else { audioSource.PlayOneShot(pickupWeapon.pickupSound, this.soundVolume); inventory.Pickup(typePickupWeapon); Destroy(collision.gameObject); } }
TypeWeapon TranslateTag(string tag) { TypeWeapon type = new TypeWeapon(); switch (tag) { case "Pistol": type = TypeWeapon.pistol; break; case "AssaultRifle": type = TypeWeapon.assaultRifle; break; case "Shotgun": type = TypeWeapon.shotgun; break; case "GrenadeGun": type = TypeWeapon.grenadeGun; break; } return(type); }
void OnGUI() { WeaponData NewItemData = (WeaponData)CreateInstance("WeaponData"); GUILayout.Label("Main editor", EditorStyles.boldLabel); if (GUILayout.Button("Refresh")) { AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); } scrollPos = EditorGUILayout.BeginScrollView(scrollPos); GUILayout.Label("Название", EditorStyles.boldLabel); NameOfItem = GUILayout.TextField(NameOfItem); if (!NameOfItem.StartsWith("W_")) { EditorGUILayout.HelpBox(" Name must start with 'W_' !", MessageType.Warning); } ChoosenSprite = (Sprite)EditorGUILayout.ObjectField("Картинка оружия", ChoosenSprite, typeof(Sprite), false); _typeWeapon = (TypeWeapon)EditorGUILayout.EnumPopup(_typeWeapon); NewItemData.TypeWeapon = (int)_typeWeapon; GUILayout.Label("Урон"); Damage = EditorGUILayout.IntSlider(Damage, 0, 100); NewItemData.Damage = Damage; GUILayout.Label("Кол-во амуниции"); MaxLoad = EditorGUILayout.IntSlider(MaxLoad, 1, 20); NewItemData.MaxLoad = MaxLoad; GUILayout.Label("Дистанция", EditorStyles.boldLabel); MaxDistance = EditorGUILayout.IntSlider("Максимальная", MaxDistance, 1, 10); NewItemData.MaxDistance = MaxDistance; NormalDistance = EditorGUILayout.IntSlider("Отимальная", NormalDistance, 1, 10); NewItemData.NormalDistance = NormalDistance; ShootPerTurn = EditorGUILayout.IntSlider("Выстрелов за ход", ShootPerTurn, 1, 10); NewItemData.BulletPerShoot = ShootPerTurn; SecondPerShoot = EditorGUILayout.FloatField("Секунд на выстрел", SecondPerShoot); NewItemData.secondPerShoot = SecondPerShoot; GUILayout.Label("Остальное", EditorStyles.boldLabel); WeaponSound = (AudioClip)EditorGUILayout.ObjectField("Звук выстрела", WeaponSound, typeof(AudioClip), false); NewItemData.WeaponSound = WeaponSound; BulletColor = EditorGUILayout.ColorField("Цвет шлейфа пули", BulletColor); NewItemData.BulletColor = BulletColor; rareType = (RareTypeEnum)EditorGUILayout.EnumPopup(rareType); NewItemData.rareType = (WeaponData.RareTypeEnum)rareType; GUILayout.Box("Cost : " + WhatACost() + "$"); if (NameOfItem.StartsWith("W_")) { CreateItem(NewItemData); } EditorGUILayout.EndScrollView(); }