This commit is contained in:
Vova
2023-07-01 11:08:57 +03:00
parent 4c1443787d
commit f674d0be26
3 changed files with 51 additions and 47 deletions
+10 -9
View File
@@ -39,10 +39,11 @@ public abstract class Character : MonoBehaviour
{
var mapElement = GetMapElement(Vector2.down);
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
{
if (mapElement == MapElementType.Wall || _isOnLadder
|| _isOnBridge || mapElement == MapElementType.BreakableWall)
{
var leftCheck = GetMapElement(Vector2.left);
var rightCheck = GetMapElement(Vector2.right);
@@ -52,7 +53,7 @@ if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElemen
isAllowVertical = false;
_isFalling = false;
float h_movement =inputHorizontal;
float h_movement = inputHorizontal;
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
{
FlipCharacter();
@@ -81,11 +82,11 @@ if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElemen
{
_body.velocity = new Vector2(h_movement * MovementSpeed, _body.velocity.y);
}
}
else
{
}
else
{
_isFalling = true;
}
}
}
@@ -95,7 +96,7 @@ else
if (raycastHit)
{
var mapElement = raycastHit.transform.GetComponent<MapElement>();
if (mapElement == null)
if (mapElement == null || !mapElement.IsEnabled)
{
return MapElementType.Empty;
}
+2 -1
View File
@@ -21,6 +21,7 @@ public class BreakableWall : MapElement
public override void Hit()
{
IsEnabled = false;
_boxCollider.isTrigger=true;
_spriteRenderer.enabled = false;
@@ -43,7 +44,7 @@ public class BreakableWall : MapElement
{
print("Character is dead");
}
IsEnabled = true;
_boxCollider.isTrigger = false;
_spriteRenderer.enabled = true;
_needRespawn = false;
+2
View File
@@ -5,6 +5,8 @@ public class MapElement : MonoBehaviour, IMapElement
[SerializeField]
private MapElementSO _elementSO;
public MapElementSO ElementSO => _elementSO;
public bool IsEnabled { get; set; } = true;
public virtual void Hit()
{