diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index ff6695f..2587b22 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -56,7 +56,7 @@ - + /D/Unity/2019.4.13f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll diff --git a/Assets/CameraController.cs b/Assets/CameraController.cs index 2527c96..a336118 100644 --- a/Assets/CameraController.cs +++ b/Assets/CameraController.cs @@ -1,38 +1,54 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; // Class for following the player with the camera public class CameraController : MonoBehaviour { // Camera speed - public float speed = 0.05f; + public float speed = 0.1f; // GameObject to be followed. public Transform target; // Our own transform - private Transform tr; + private Transform _tr; // Center position of the target relative to the camera. public Vector3 offset; + private float _lastSwitch = -1; + private bool _facingRight; // Store initial values void Start() { - tr = transform; - offset = target.position - tr.position; + _tr = transform; + offset = target.position - _tr.position; } // Update positions - void FixedUpdate () + void FixedUpdate() { if (!target) return; // Get where the camera should be, and what movement is required. - var position = tr.position; - Vector3 anchorPos = position + offset; + var position = _tr.position; + bool facingLeft = target.localScale.x < 0; + Vector3 anchorPos = position + (facingLeft ? new Vector3(-offset.x, offset.y, offset.z) : offset); Vector3 movement = target.position - anchorPos; + float sp = speed; + /*if (_lastSwitch >= 0 && Time.time - _lastSwitch < 0.5f) + sp /= 4;*/ + float diff = Time.time - _lastSwitch; + if (_lastSwitch >= 0 && diff < 2f) + sp *= 0.5f + diff / 4; + + if (facingLeft == _facingRight) //Megváltozott az irány + _lastSwitch = Time.time; + + _facingRight = !facingLeft; + // Update position based on movement and speed. - Vector3 newCamPos = position + movement*speed; + Vector3 newCamPos = position + movement * sp; position = newCamPos; - tr.position = position; + _tr.position = position; } } \ No newline at end of file diff --git a/Assets/CharacterController.cs b/Assets/CharacterController.cs deleted file mode 100644 index 420dbb0..0000000 --- a/Assets/CharacterController.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class CharacterController : MonoBehaviour -{ - private Rigidbody2D rb; - - // Start is called before the first frame update - void Start() - { - rb = GetComponent(); - } - - // Update is called once per frame - void Update() - { - if (Mathf.Abs(rb.velocity.x) > 10) - return; - rb.AddForce(new Vector2(Input.GetAxis("Horizontal") * 5, 0)); - } -} \ No newline at end of file diff --git a/Assets/OwnCharacterController.cs b/Assets/OwnCharacterController.cs new file mode 100644 index 0000000..924f364 --- /dev/null +++ b/Assets/OwnCharacterController.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +public class OwnCharacterController : MonoBehaviour +{ + private Rigidbody2D rb; + private Collider2D collider; + + // Start is called before the first frame update + void Start() + { + rb = GetComponent(); + collider = GetComponent(); + } + + // Update is called once per frame + void Update() + { + if (Mathf.Abs(rb.velocity.x) > 3) + return; + float input = Input.GetAxis("Horizontal"); + if (input < 0 && rb.transform.localScale.x > 0 + || input > 0 && rb.transform.localScale.x < 0) + { + var tr = transform; + var scale = tr.localScale; + scale.x *= -1; + tr.localScale = scale; + } + rb.AddForce(new Vector2(input * 5, 0)); + + var cols = new Collider2D[5]; + /*if (Input.GetButtonDown("Jump") && rb.OverlapCollider(new ContactFilter2D(), cols) > 0 + && cols.Any(col => col.CompareTag("Tiled")))*/ + if (Input.GetButtonDown("Jump") && IsOnGround()) + rb.AddForce(new Vector2(0, 3), ForceMode2D.Impulse); + } + + private bool IsOnGround() + { + var bounds = collider.bounds; + return Physics.CheckCapsule(bounds.center, new Vector3(bounds.center.x, bounds.min.y - 0.1f, bounds.center.z), + 0.28f); + } +} \ No newline at end of file diff --git a/Assets/CharacterController.cs.meta b/Assets/OwnCharacterController.cs.meta similarity index 100% rename from Assets/CharacterController.cs.meta rename to Assets/OwnCharacterController.cs.meta diff --git a/Assets/Sprites/backgroundColorFall.png b/Assets/Sprites/backgroundColorFall.png deleted file mode 100644 index bc7e2a6..0000000 Binary files a/Assets/Sprites/backgroundColorFall.png and /dev/null differ diff --git a/Assets/Sprites/backgroundColorFall.png.meta b/Assets/Sprites/backgroundColorFall.png.meta deleted file mode 100644 index 485401c..0000000 --- a/Assets/Sprites/backgroundColorFall.png.meta +++ /dev/null @@ -1,92 +0,0 @@ -fileFormatVersion: 2 -guid: 5fa1bba7bbdf8890ab8dcb6ee0f1cef2 -TextureImporter: - internalIDToNameTable: [] - 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 - grayScaleToAlpha: 0 - generateCubemap: 6 - cubemapConvolution: 0 - seamlessCubemap: 0 - textureFormat: 1 - maxTextureSize: 2048 - textureSettings: - serializedVersion: 2 - filterMode: -1 - aniso: -1 - mipBias: -100 - 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: 100 - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spriteGenerateFallbackPhysicsShape: 1 - alphaUsage: 1 - alphaIsTransparency: 1 - spriteTessellationDetail: -1 - textureType: 8 - textureShape: 1 - singleChannelComponent: 0 - maxTextureSizeSet: 0 - compressionQualitySet: 0 - textureFormatSet: 0 - applyGammaDecoding: 0 - platformSettings: - - serializedVersion: 3 - buildTarget: DefaultTexturePlatform - maxTextureSize: 2048 - resizeAlgorithm: 0 - textureFormat: -1 - textureCompression: 1 - compressionQuality: 50 - crunchedCompression: 0 - allowsAlphaSplitting: 0 - overridden: 0 - androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 0 - spriteSheet: - serializedVersion: 2 - sprites: [] - outline: [] - physicsShape: [] - bones: [] - spriteID: 5e97eb03825dee720800000000000000 - internalID: 0 - vertices: [] - indices: - edges: [] - weights: [] - secondaryTextures: [] - spritePackingTag: - pSDRemoveMatte: 0 - pSDShowRemoveMatteOption: 0 - userData: - assetBundleName: - assetBundleVariant: