Destroyable tile blocks with TilesExtra
still issues with collider
This commit is contained in:
@@ -36,7 +36,7 @@ public class Character : MonoBehaviour
|
||||
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
||||
|
||||
float v_movement=0;
|
||||
if (mapElement==MapElementType.Wall || _isOnLadder || _isOnBridge)
|
||||
if (mapElement==MapElementType.Wall || _isOnLadder || _isOnBridge|| mapElement == MapElementType.BreakableWall)
|
||||
{
|
||||
var leftCheck = GetMapElement(Vector2.left);
|
||||
var rightCheck = GetMapElement(Vector2.right);
|
||||
@@ -93,7 +93,7 @@ public class Character : MonoBehaviour
|
||||
|
||||
private MapElementType GetMapElement(Vector2 direction)
|
||||
{
|
||||
var raycastHit=Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, .1f, _mapLayer);
|
||||
var raycastHit=Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, 0.1f, _mapLayer);
|
||||
if (raycastHit)
|
||||
{
|
||||
|
||||
|
||||
@@ -12,10 +12,12 @@ public class Hammer : MonoBehaviour
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
var player = collision.collider.GetComponent<Player>();
|
||||
if (player == null)
|
||||
var mapElement = collision.collider.GetComponent<MapElement>();
|
||||
if (mapElement?.ElementSO.ElementType==MapElementType.BreakableWall)
|
||||
{
|
||||
Destroy(collision.gameObject);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,4 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 541209b3a8828a3429d3a6c93b0350f3, type: 3}
|
||||
m_Name: BreakableWall
|
||||
m_EditorClassIdentifier:
|
||||
ElementType: 0
|
||||
ElementType: 4
|
||||
|
||||
@@ -1,8 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MapElement:MonoBehaviour
|
||||
public class MapElement : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private MapElementSO _elementSO;
|
||||
public MapElementSO ElementSO => _elementSO;
|
||||
}
|
||||
|
||||
private float _respawnElementTimer;
|
||||
private int _respawnTimeout = 4;
|
||||
private bool _needRespawn = false;
|
||||
public void Hit()
|
||||
{
|
||||
gameObject.GetComponent<BoxCollider2D>().enabled = false;
|
||||
_needRespawn = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_needRespawn)
|
||||
{
|
||||
_respawnElementTimer -= Time.deltaTime;
|
||||
if (_respawnElementTimer <= 0)
|
||||
{
|
||||
_respawnElementTimer = _respawnTimeout;
|
||||
gameObject.GetComponent<BoxCollider2D>().enabled = true;
|
||||
_needRespawn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user