Добавить несколько различных видов оружия (2-3) с возможность переключения между ними.
This commit is contained in:
parent
87aaf3139a
commit
7a155dfb5e
8
Assets/Low Poly Guns/Models/Guns/pistol1/Materials.meta
Normal file
8
Assets/Low Poly Guns/Models/Guns/pistol1/Materials.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d23e874ed4dd7d4c83138fecc6b4ee7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,137 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &-1619176616180333941
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
|
||||
version: 10
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: pistol1_diffuse
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses:
|
||||
- MOTIONVECTORS
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 2800000, guid: 0d6b1249a62d53f4e8900c84722db1f8, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: 0d6b1249a62d53f4e8900c84722db1f8, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AddPrecomputedVelocity: 0
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _XRMotionVectorsPass: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 655ff3771f10c6b4c998fc29edcc4499
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -2,23 +2,34 @@
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: pistol1
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords: _NORMALMAP
|
||||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords:
|
||||
- _NORMALMAP
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
stringTagMap:
|
||||
RenderType: Opaque
|
||||
disabledShaderPasses:
|
||||
- MOTIONVECTORS
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 2800000, guid: a21b6f6faa594df4fa1cb1794a16a4b3, type: 3}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
@ -40,7 +51,7 @@ Material:
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 2800000, guid: 0d6b1249a62d53f4e8900c84722db1f8, type: 3}
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
@ -55,11 +66,39 @@ Material:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AddPrecomputedVelocity: 0
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.565
|
||||
- _GlossyReflections: 1
|
||||
@ -67,11 +106,22 @@ Material:
|
||||
- _Mode: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.02
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _UVSec: 0
|
||||
- _WorkflowMode: 1
|
||||
- _XRMotionVectorsPass: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
m_AllowLocking: 1
|
||||
|
||||
BIN
Assets/Low Poly Guns/cd876701a06be1f.mp3
Normal file
BIN
Assets/Low Poly Guns/cd876701a06be1f.mp3
Normal file
Binary file not shown.
23
Assets/Low Poly Guns/cd876701a06be1f.mp3.meta
Normal file
23
Assets/Low Poly Guns/cd876701a06be1f.mp3.meta
Normal file
@ -0,0 +1,23 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 719e03360b48a75429798219d632bd77
|
||||
AudioImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 8
|
||||
defaultSettings:
|
||||
serializedVersion: 2
|
||||
loadType: 0
|
||||
sampleRateSetting: 0
|
||||
sampleRateOverride: 44100
|
||||
compressionFormat: 1
|
||||
quality: 1
|
||||
conversionMode: 0
|
||||
preloadAudioData: 0
|
||||
platformSettingOverrides: {}
|
||||
forceToMono: 0
|
||||
normalize: 1
|
||||
loadInBackground: 0
|
||||
ambisonic: 0
|
||||
3D: 1
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -649,7 +649,7 @@ RectTransform:
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: -741, y: -392}
|
||||
m_SizeDelta: {x: 200, y: 50}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &345079589
|
||||
@ -699,8 +699,8 @@ MonoBehaviour:
|
||||
m_faceColor:
|
||||
serializedVersion: 2
|
||||
rgba: 4294967295
|
||||
m_fontSize: 36
|
||||
m_fontSizeBase: 36
|
||||
m_fontSize: 78.7
|
||||
m_fontSizeBase: 78.7
|
||||
m_fontWeight: 400
|
||||
m_enableAutoSizing: 0
|
||||
m_fontSizeMin: 18
|
||||
@ -738,7 +738,7 @@ MonoBehaviour:
|
||||
m_VertexBufferAutoSizeReduction: 0
|
||||
m_useMaxVisibleDescender: 1
|
||||
m_pageToDisplay: 1
|
||||
m_margin: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_margin: {x: -51.073425, y: -63.097504, z: -704.7418, w: 0}
|
||||
m_isUsingLegacyAnimationComponent: 0
|
||||
m_isVolumetricText: 0
|
||||
m_hasFontAssetChanged: 0
|
||||
@ -1025,7 +1025,7 @@ MonoBehaviour:
|
||||
maxAmmo: 5
|
||||
reloadTime: 1.5
|
||||
muzzleFlashSprite: {fileID: 0}
|
||||
ammoText: {fileID: 0}
|
||||
ammoText: {fileID: 345079589}
|
||||
reloadSound: {fileID: 8300000, guid: 52f0e026b4e684842a21cf732eb9f286, type: 3}
|
||||
--- !u!114 &507701288
|
||||
MonoBehaviour:
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
// ИЗМЕНЕНО: Используем пространство имен для TextMeshPro
|
||||
using TMPro;
|
||||
|
||||
public class PlayerShooting : MonoBehaviour
|
||||
@ -19,7 +18,6 @@ public class PlayerShooting : MonoBehaviour
|
||||
|
||||
// --- Ссылки на компоненты и объекты ---
|
||||
public GameObject muzzleFlashSprite;
|
||||
// ИЗМЕНЕНО: Тип переменной заменен на TextMeshProUGUI
|
||||
public TextMeshProUGUI ammoText;
|
||||
public AudioClip reloadSound;
|
||||
|
||||
@ -32,6 +30,15 @@ public class PlayerShooting : MonoBehaviour
|
||||
private AudioSource gunAudio;
|
||||
private Light gunLight;
|
||||
|
||||
// НОВЫЙ МЕТОД: Вызывается каждый раз, когда оружие становится активным
|
||||
void OnEnable()
|
||||
{
|
||||
// Прерываем перезарядку, если игрок переключился на это оружие
|
||||
isReloading = false;
|
||||
// Немедленно обновляем текст с количеством патронов
|
||||
UpdateAmmoText();
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
shootableMask = LayerMask.GetMask("Shootable");
|
||||
@ -43,9 +50,9 @@ public class PlayerShooting : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Инициализируем патроны только один раз при первом запуске
|
||||
currentAmmo = maxAmmo;
|
||||
UpdateAmmoText();
|
||||
|
||||
|
||||
if (gunLight != null) gunLight.enabled = false;
|
||||
if (muzzleFlashSprite != null) muzzleFlashSprite.SetActive(false);
|
||||
}
|
||||
@ -151,7 +158,6 @@ public class PlayerShooting : MonoBehaviour
|
||||
{
|
||||
if (ammoText != null)
|
||||
{
|
||||
// Для TextMeshPro синтаксис точно такой же, так что здесь ничего менять не нужно
|
||||
ammoText.text = "Патроны: " + currentAmmo + " / " + maxAmmo;
|
||||
}
|
||||
}
|
||||
|
||||
73
Assets/Scripts/WeaponSwitcher.cs
Normal file
73
Assets/Scripts/WeaponSwitcher.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WeaponSwitcher : MonoBehaviour
|
||||
{
|
||||
// Массив, в котором будут храниться все наши объекты-оружия
|
||||
public GameObject[] weapons;
|
||||
private int currentWeaponIndex = 0;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// При запуске игры выбираем первое оружие
|
||||
SwitchWeapon(0);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// --- Переключение с помощью цифровых клавиш ---
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
SwitchWeapon(0);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2) && weapons.Length >= 2)
|
||||
{
|
||||
SwitchWeapon(1);
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha3) && weapons.Length >= 3)
|
||||
{
|
||||
SwitchWeapon(2);
|
||||
}
|
||||
|
||||
// --- Переключение с помощью колеса мыши ---
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (scroll > 0f) // Прокрутка вверх
|
||||
{
|
||||
currentWeaponIndex++;
|
||||
if (currentWeaponIndex >= weapons.Length)
|
||||
{
|
||||
currentWeaponIndex = 0; // Возвращаемся к первому
|
||||
}
|
||||
SwitchWeapon(currentWeaponIndex);
|
||||
}
|
||||
else if (scroll < 0f) // Прокрутка вниз
|
||||
{
|
||||
currentWeaponIndex--;
|
||||
if (currentWeaponIndex < 0)
|
||||
{
|
||||
currentWeaponIndex = weapons.Length - 1; // Переходим к последнему
|
||||
}
|
||||
SwitchWeapon(currentWeaponIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchWeapon(int newIndex)
|
||||
{
|
||||
// Проверяем, что индекс в пределах массива
|
||||
if (newIndex < 0 || newIndex >= weapons.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Выключаем все оружия
|
||||
for (int i = 0; i < weapons.Length; i++)
|
||||
{
|
||||
weapons[i].SetActive(false);
|
||||
}
|
||||
|
||||
// Включаем только нужное
|
||||
weapons[newIndex].SetActive(true);
|
||||
|
||||
// Обновляем текущий индекс
|
||||
currentWeaponIndex = newIndex;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/WeaponSwitcher.cs.meta
Normal file
2
Assets/Scripts/WeaponSwitcher.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84d3169ccc0af7845ba1ae97fcd55584
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user