diff --git a/Blocktest/Assets/Resources/Animations.meta b/Blocktest/Assets/Resources/Animations.meta new file mode 100644 index 0000000..bfc32fd --- /dev/null +++ b/Blocktest/Assets/Resources/Animations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d886f8294d0866d4292d197aacbc06ae +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Blocktest/Assets/Resources/Animations/Player.controller b/Blocktest/Assets/Resources/Animations/Player.controller new file mode 100644 index 0000000..d9a525a --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player.controller @@ -0,0 +1,12 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!91 &9100000 +AnimatorController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Player + serializedVersion: 5 + m_AnimatorParameters: [] + m_AnimatorLayers: [] diff --git a/Blocktest/Assets/Resources/Animations/Player.controller.meta b/Blocktest/Assets/Resources/Animations/Player.controller.meta new file mode 100644 index 0000000..d8864f7 --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player.controller.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fca24237ae0587540b9b4dfe58c15694 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 9100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Blocktest/Assets/Resources/Animations/Player_idle.anim b/Blocktest/Assets/Resources/Animations/Player_idle.anim new file mode 100644 index 0000000..722b3de --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player_idle.anim @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Player_idle + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: [] + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: [] + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Blocktest/Assets/Resources/Animations/Player_idle.anim.meta b/Blocktest/Assets/Resources/Animations/Player_idle.anim.meta new file mode 100644 index 0000000..6ce4382 --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player_idle.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9f47769fff459d54b94735de099d0781 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 7400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Blocktest/Assets/Resources/Animations/Player_walk.anim b/Blocktest/Assets/Resources/Animations/Player_walk.anim new file mode 100644 index 0000000..41cd283 --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player_walk.anim @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Player_walk + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: [] + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: [] + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Blocktest/Assets/Resources/Animations/Player_walk.anim.meta b/Blocktest/Assets/Resources/Animations/Player_walk.anim.meta new file mode 100644 index 0000000..2138359 --- /dev/null +++ b/Blocktest/Assets/Resources/Animations/Player_walk.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 25badab9c99ceff459061df907681b4e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 7400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Blocktest/Assets/Resources/Sprites/player_walk.png b/Blocktest/Assets/Resources/Sprites/player_walk.png new file mode 100644 index 0000000..885bf30 Binary files /dev/null and b/Blocktest/Assets/Resources/Sprites/player_walk.png differ diff --git a/Blocktest/Assets/Resources/Sprites/player_walk.png.meta b/Blocktest/Assets/Resources/Sprites/player_walk.png.meta new file mode 100644 index 0000000..c913f43 --- /dev/null +++ b/Blocktest/Assets/Resources/Sprites/player_walk.png.meta @@ -0,0 +1,324 @@ +fileFormatVersion: 2 +guid: 994db6e82a1eab546bebe295364e6404 +TextureImporter: + internalIDToNameTable: + - first: + 213: 2215745761463138581 + second: player_walk_0 + - first: + 213: 1700766857389022521 + second: player_walk_1 + - first: + 213: 2457880308640484884 + second: player_walk_2 + - first: + 213: -1273090703572220712 + second: player_walk_3 + - first: + 213: 7775377318884447243 + second: player_walk_4 + - first: + 213: -5374289345228034197 + second: player_walk_5 + - first: + 213: 765823781208195064 + second: player_walk_6 + - first: + 213: 535955826551466408 + second: player_walk_7 + externalObjects: {} + serializedVersion: 11 + 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 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 0 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 2 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 16 + 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 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Windows Store Apps + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: + - serializedVersion: 2 + name: player_walk_0 + rect: + serializedVersion: 2 + x: 0 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 5197690d709efbe10800000000000000 + internalID: 2215745761463138581 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_1 + rect: + serializedVersion: 2 + x: 16 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 93d1e6c12765a9710800000000000000 + internalID: 1700766857389022521 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_2 + rect: + serializedVersion: 2 + x: 32 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 41e81f84e152c1220800000000000000 + internalID: 2457880308640484884 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_3 + rect: + serializedVersion: 2 + x: 48 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 8d4c9be00c2155ee0800000000000000 + internalID: -1273090703572220712 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_4 + rect: + serializedVersion: 2 + x: 64 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: b049cbec970b7eb60800000000000000 + internalID: 7775377318884447243 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_5 + rect: + serializedVersion: 2 + x: 80 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: b6f24819050ba65b0800000000000000 + internalID: -5374289345228034197 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_6 + rect: + serializedVersion: 2 + x: 96 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 8fff577eba0c0aa00800000000000000 + internalID: 765823781208195064 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: player_walk_7 + rect: + serializedVersion: 2 + x: 112 + y: 0 + width: 16 + height: 32 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: 0 + bones: [] + spriteID: 8a9a6e01cf8107700800000000000000 + internalID: 535955826551466408 + vertices: [] + indices: + edges: [] + weights: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Blocktest/Assets/Scripts/PlayerController.cs b/Blocktest/Assets/Scripts/PlayerController.cs index 2227a3d..f444b9a 100644 --- a/Blocktest/Assets/Scripts/PlayerController.cs +++ b/Blocktest/Assets/Scripts/PlayerController.cs @@ -10,24 +10,40 @@ public class PlayerController : MonoBehaviour [SerializeField] float jumpStrength = 7.5f; [SerializeField] LayerMask groundLayer; /// Rigidbody component of the player - private Rigidbody2D playerRB; + private Rigidbody2D playerRigidBody; + /// Animator component of the player + private Animator playerAnimator; + /// Sprite renderer component of the player + private SpriteRenderer playerSpriteRenderer; // Start is called before the first frame update void Start() { - playerRB = GetComponent(); + playerRigidBody = GetComponent(); + playerAnimator = GetComponent(); + playerSpriteRenderer = GetComponent(); } // Update is called once per frame void Update() { float horizontalInput = Input.GetAxis("Horizontal"); - if(horizontalInput != 0) - { - playerRB.velocity = new Vector2(horizontalInput * moveSpeed, playerRB.velocity.y); + bool onGround = (playerRigidBody.GetContacts(new List()) > 0); // Checks if the player is colliding with ANYTHING + + playerAnimator.SetFloat("MoveSpeed", Mathf.Abs(horizontalInput)); + playerAnimator.SetFloat("VerticalSpeed", playerRigidBody.velocity.y); + + if(horizontalInput != 0){ + playerRigidBody.velocity = new Vector2(horizontalInput * moveSpeed, playerRigidBody.velocity.y); + + if(horizontalInput > 0) { + playerSpriteRenderer.flipX = false; + } else { + playerSpriteRenderer.flipX = true; + } + } - if(Input.GetKeyDown(KeyCode.Space) && (playerRB.GetContacts(new List()) > 0)) // Checks to see if the player is colliding with ANYTHING - { - playerRB.AddForce(Vector2.up * jumpStrength, ForceMode2D.Impulse); + if(Input.GetButtonDown("Jump") && onGround) { + playerRigidBody.AddForce(Vector2.up * jumpStrength, ForceMode2D.Impulse); } } }