diff --git a/Assets/Animations/Player.controller b/Assets/Animations/Player.controller index 197323e..7da7915 100644 --- a/Assets/Animations/Player.controller +++ b/Assets/Animations/Player.controller @@ -120,7 +120,7 @@ AnimatorController: m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer diff --git a/Assets/Prefabs/Hammer.prefab b/Assets/Prefabs/Hammer.prefab index 2a566ae..91a8ddf 100644 --- a/Assets/Prefabs/Hammer.prefab +++ b/Assets/Prefabs/Hammer.prefab @@ -1,6 +1,6 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!1 &2958021263621857452 +--- !u!1 &2057671621019232995 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -8,37 +8,119 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 2454187666574255262} - - component: {fileID: 8181499430146844313} + - component: {fileID: 4578345404272006982} + - component: {fileID: 3947387574655652828} m_Layer: 0 - m_Name: Circle + m_Name: Light 2D m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!4 &2454187666574255262 +--- !u!4 &4578345404272006982 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2958021263621857452} + m_GameObject: {fileID: 2057671621019232995} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -0.1372965} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 1 + m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 489085077110977200} m_RootOrder: -1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!212 &8181499430146844313 +--- !u!114 &3947387574655652828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2057671621019232995} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 073797afb82c5a1438f328866b10b3f0, type: 3} + m_Name: + m_EditorClassIdentifier: + m_ComponentVersion: 1 + m_LightType: 3 + m_BlendStyleIndex: 0 + m_FalloffIntensity: 0.748 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 1 + m_LightVolumeIntensity: 1 + m_LightVolumeIntensityEnabled: 0 + m_ApplyToSortingLayers: 00000000413d3badebb708f897fdd82d8315a380 + m_LightCookieSprite: {fileID: 21300000, guid: 766cfa1430bc448ed93c5817e7682f3b, type: 3} + m_DeprecatedPointLightCookieSprite: {fileID: 0} + m_LightOrder: 0 + m_AlphaBlendOnOverlap: 0 + m_OverlapOperation: 0 + m_NormalMapDistance: 3 + m_NormalMapQuality: 2 + m_UseNormalMap: 0 + m_ShadowIntensityEnabled: 0 + m_ShadowIntensity: 0.75 + m_ShadowVolumeIntensityEnabled: 0 + m_ShadowVolumeIntensity: 0.75 + m_LocalBounds: + m_Center: {x: 0, y: -0.00000011920929, z: 0} + m_Extent: {x: 0.9985302, y: 0.99853027, z: 0} + m_PointLightInnerAngle: 360 + m_PointLightOuterAngle: 360 + m_PointLightInnerRadius: 0 + m_PointLightOuterRadius: 1 + m_ShapeLightParametricSides: 5 + m_ShapeLightParametricAngleOffset: 0 + m_ShapeLightParametricRadius: 1 + m_ShapeLightFalloffSize: 0.5 + m_ShapeLightFalloffOffset: {x: 0, y: 0} + m_ShapePath: + - {x: -0.5, y: -0.5, z: 0} + - {x: 0.5, y: -0.5, z: 0} + - {x: 0.5, y: 0.5, z: 0} + - {x: -0.5, y: 0.5, z: 0} +--- !u!1 &4217097808196132424 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2841508695468556490} + - component: {fileID: 593132000161094840} + m_Layer: 0 + m_Name: Hammer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2841508695468556490 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4217097808196132424} + m_LocalRotation: {x: -0, y: -0, z: -0.4685917, w: 0.8834149} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1.8333333, y: 1.8333333, z: 3.333333} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 489085077110977200} + m_RootOrder: -1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: -55.886} +--- !u!212 &593132000161094840 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2958021263621857452} + m_GameObject: {fileID: 4217097808196132424} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -70,15 +152,15 @@ SpriteRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 769195415 - m_SortingLayer: 3 + m_SortingLayerID: -2136795773 + m_SortingLayer: 4 m_SortingOrder: 0 - m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3} + m_Sprite: {fileID: 21300000, guid: 401f49f49f3f94c44b2cbb6bc974f321, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 1, y: 1} + m_Size: {x: 2.64, y: 3.01} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -115,9 +197,10 @@ Transform: m_LocalScale: {x: 0.3, y: 0.3, z: 0.3} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 2454187666574255262} + - {fileID: 2841508695468556490} + - {fileID: 4578345404272006982} m_Father: {fileID: 0} - m_RootOrder: 6 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!50 &2933422370826313773 Rigidbody2D: @@ -131,7 +214,7 @@ Rigidbody2D: m_Simulated: 1 m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 - m_Mass: 1 + m_Mass: 0.2 m_LinearDrag: 0 m_AngularDrag: 0.05 m_GravityScale: 0 diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 269a8bd..11048ba 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -244,7 +244,7 @@ Rigidbody2D: m_Simulated: 1 m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 - m_Mass: 0.0001 + m_Mass: 1 m_LinearDrag: 0 m_AngularDrag: 0 m_GravityScale: 1 @@ -573,7 +573,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7780229847895093112} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.401, y: -0.137, z: 0} + m_LocalPosition: {x: 0.307, y: 0.006, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 93871de..b094745 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -12,11 +12,11 @@ public class Character : MonoBehaviour private Rigidbody2D _body; private BoxCollider2D _boxCollider; - - private bool _isOnBridge; - private bool _isOnLadder; - private bool _isFalling; - private bool _facingRight = true; + + protected bool _isOnBridge; + protected bool _isOnLadder; + protected bool _isFalling; + protected bool _facingRight = true; protected bool isAllowVertical = true; diff --git a/Assets/Scripts/Hammer.cs b/Assets/Scripts/Hammer.cs index c777a29..1e1833f 100644 --- a/Assets/Scripts/Hammer.cs +++ b/Assets/Scripts/Hammer.cs @@ -1,5 +1,3 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class Hammer : MonoBehaviour @@ -12,10 +10,14 @@ public class Hammer : MonoBehaviour private void OnCollisionEnter2D(Collision2D collision) { - var mapElement = collision.collider.GetComponent(); + var mapElement = collision.collider.GetComponent(); + if(mapElement!=null) + { + Destroy(gameObject); + } if (mapElement?.ElementSO.ElementType==MapElementType.BreakableWall) { - Destroy(collision.gameObject); + mapElement.Hit(); Destroy(gameObject); } } diff --git a/Assets/Scripts/MapElements/MapElement.cs b/Assets/Scripts/MapElements/MapElement.cs index a72b05b..281e44d 100644 --- a/Assets/Scripts/MapElements/MapElement.cs +++ b/Assets/Scripts/MapElements/MapElement.cs @@ -9,9 +9,13 @@ public class MapElement : MonoBehaviour private float _respawnElementTimer; private int _respawnTimeout = 4; private bool _needRespawn = false; + public void Hit() { - gameObject.GetComponent().enabled = false; + gameObject.GetComponent().enabled=false; + gameObject.GetComponentInChildren().enabled = false; + + _respawnElementTimer = _respawnTimeout; _needRespawn = true; } @@ -24,9 +28,9 @@ public class MapElement : MonoBehaviour { _respawnElementTimer = _respawnTimeout; gameObject.GetComponent().enabled = true; + gameObject.GetComponentInChildren().enabled = true; _needRespawn = false; } } } - } \ No newline at end of file diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index a3a4031..be8ae30 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -7,13 +7,13 @@ public class Player : Character [SerializeField] private GameObject _hammerPrefab; - private int _hammerSpeed=10; + private int _hammerSpeed = 10; private int _totalCoins = 0; private bool _hasKey = false; public static Player Instance { get; private set; } - + private GameObject _hammer; private void Awake() { @@ -29,7 +29,6 @@ public class Player : Character DontDestroyOnLoad(gameObject); } - public void AddCoin() { _totalCoins++; @@ -39,7 +38,7 @@ public class Player : Character public void SetKey() { print($"player have key"); - _hasKey =true; + _hasKey = true; } public void RemoveKey() @@ -54,10 +53,14 @@ public class Player : Character private void Update() { - if (Input.GetKeyDown(KeyCode.Space)) + if (Input.GetKeyDown(KeyCode.Space) && !_isFalling) { - var hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation); - hammer.GetComponent().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed,0); + if (_hammer == null) + { + _hammer = Instantiate(_hammerPrefab, _hammerSpawnPoint.position, _hammerSpawnPoint.rotation); + _hammer.transform.localScale = new Vector2(_hammer.transform.localScale.x * (_facingRight ? 1 : -1), _hammer.transform.localScale.y); + _hammer.GetComponent().velocity = new Vector2(gameObject.transform.localScale.x * _hammerSpeed, 0); + } } base.MoveTo(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); } diff --git a/Assets/Sprites/Hammer.png b/Assets/Sprites/Hammer.png new file mode 100644 index 0000000..13fdca2 Binary files /dev/null and b/Assets/Sprites/Hammer.png differ diff --git a/Assets/Sprites/Hammer.png.meta b/Assets/Sprites/Hammer.png.meta new file mode 100644 index 0000000..94cdcc1 --- /dev/null +++ b/Assets/Sprites/Hammer.png.meta @@ -0,0 +1,127 @@ +fileFormatVersion: 2 +guid: 401f49f49f3f94c44b2cbb6bc974f321 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 400 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: