diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index cbfa018..e9d09ab 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -26,7 +26,7 @@ public abstract class Character : MonoBehaviour protected bool _isFalling; protected bool _facingRight = true; - + protected bool isCanClimbUp=false; protected bool isAllowVertical = true; protected bool isAllowRight = true; protected bool isAllowLeft = true; @@ -73,17 +73,25 @@ public abstract class Character : MonoBehaviour if (_isOnLadder) { + isCanClimbUp=CanClimbUp(); + float ladderXCenterDistance = Mathf.Abs(transform.position.x - block.transform.position.x); float v_movement = inputVertical; - + isAllowVertical = (ladderXCenterDistance < 0.3f); + if(!isCanClimbUp&& v_movement>0) + { + v_movement=0; + } - isAllowVertical = (ladderXCenterDistance < 0.3f) || (CanClimbUp() && v_movement>0); if (isAllowVertical) { SetClimbingAnimation(v_movement != 0); _body.velocity = new Vector2(h_movement * _movementSpeed, v_movement * _movementSpeed); } + else{ + _body.velocity = new Vector2(h_movement * _movementSpeed, _body.velocity.y); + } } else { diff --git a/Assets/Scripts/EnemyAI.cs b/Assets/Scripts/EnemyAI.cs index 6f7e135..a50a14c 100644 --- a/Assets/Scripts/EnemyAI.cs +++ b/Assets/Scripts/EnemyAI.cs @@ -20,18 +20,22 @@ public class EnemyAI : Character float horizontal = 0; float vertical = 0; - Vector2 directionToPlayer = Player.Instance.transform.position - transform.position; + Vector2 directionToPlayer = Player.Instance.transform.position - transform.position; directionToPlayer.Normalize(); + float verticalDistance = Player.Instance.transform.position.y - transform.position.y; + if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) < 0.1f) { horizontal = directionToPlayer.x; } - else if (isAllowVertical) + else if (verticalDistance>0 && isCanClimbUp && isAllowVertical) { - float verticalDistance = Player.Instance.transform.position.y - transform.position.y; - float verticalDirection = Mathf.Sign(verticalDistance); - vertical = verticalDirection; + vertical =VerticalMove(verticalDistance); + } + else if (verticalDistance<0 && isAllowVertical) + { + vertical =VerticalMove(verticalDistance); } else { @@ -48,4 +52,10 @@ public class EnemyAI : Character { vertical = -1; } base.MoveTo(horizontal, vertical); } + + private float VerticalMove(float verticalDistance) + { + float verticalDirection = Mathf.Sign(verticalDistance); + return verticalDirection; + } } diff --git a/Packages/manifest.json b/Packages/manifest.json index 3d833c3..a0af090 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -8,17 +8,17 @@ "com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap.extras": "3.1.1", "com.unity.ads": "4.4.2", - "com.unity.ai.navigation": "1.1.3", + "com.unity.ai.navigation": "1.1.4", "com.unity.analytics": "3.8.1", - "com.unity.collab-proxy": "2.0.4", - "com.unity.ide.rider": "3.0.21", + "com.unity.collab-proxy": "2.0.5", + "com.unity.ide.rider": "3.0.24", "com.unity.ide.visualstudio": "2.0.18", "com.unity.ide.vscode": "1.2.5", - "com.unity.purchasing": "4.8.0", + "com.unity.purchasing": "4.9.3", "com.unity.render-pipelines.universal": "14.0.8", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.7.4", + "com.unity.timeline": "1.7.5", "com.unity.ugui": "1.0.0", "com.unity.xr.legacyinputhelpers": "2.1.10", "com.unity.modules.ai": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 2fa8c7b..7788cfa 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -92,7 +92,7 @@ "url": "https://packages.unity.com" }, "com.unity.ai.navigation": { - "version": "1.1.3", + "version": "1.1.4", "depth": 0, "source": "registry", "dependencies": { @@ -111,7 +111,7 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.8.4", + "version": "1.8.7", "depth": 1, "source": "registry", "dependencies": { @@ -120,7 +120,7 @@ "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "2.0.4", + "version": "2.0.5", "depth": 0, "source": "registry", "dependencies": {}, @@ -144,7 +144,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.rider": { - "version": "3.0.21", + "version": "3.0.24", "depth": 0, "source": "registry", "dependencies": { @@ -183,7 +183,7 @@ "url": "https://packages.unity.com" }, "com.unity.purchasing": { - "version": "4.8.0", + "version": "4.9.3", "depth": 0, "source": "registry", "dependencies": { @@ -226,18 +226,18 @@ "url": "https://packages.unity.com" }, "com.unity.services.analytics": { - "version": "4.4.0", + "version": "5.0.0", "depth": 1, "source": "registry", "dependencies": { "com.unity.ugui": "1.0.0", - "com.unity.services.core": "1.8.1", - "com.unity.nuget.newtonsoft-json": "3.0.2" + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.services.core": "1.10.1" }, "url": "https://packages.unity.com" }, "com.unity.services.core": { - "version": "1.9.0", + "version": "1.10.1", "depth": 1, "source": "registry", "dependencies": { @@ -277,7 +277,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.7.4", + "version": "1.7.5", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/Packages/com.unity.services.core/Settings.json b/ProjectSettings/Packages/com.unity.services.core/Settings.json new file mode 100644 index 0000000..e69de29