move to 3d

This commit is contained in:
2026-06-22 17:04:35 +03:00
parent 5fbe7391d3
commit 57ac96e577
7 changed files with 440 additions and 513 deletions
+29
View File
@@ -1,3 +1,4 @@
using System.Collections;
using UnityEngine;
public class Hammer : MonoBehaviour
@@ -8,6 +9,8 @@ public class Hammer : MonoBehaviour
private bool _hasCollided = false;
private Rigidbody2D _rigidbody;
private Collider2D _collider;
private bool _canHit = false;
private Coroutine _disableHitCoroutine;
private void Awake()
{
@@ -61,6 +64,11 @@ public class Hammer : MonoBehaviour
private void ProcessHit(Collider2D collider, Vector2 impactVelocity, Vector2 contactPoint)
{
// Only process hits when the hammer is allowed to hit (activated by input)
if (!_canHit)
return;
StartCoroutine(ResetCollisionCoroutine());
// Check for enemy collision (stun)
var enemy = collider.gameObject.GetComponent<Character>();
if (enemy != null)
@@ -83,6 +91,21 @@ public class Hammer : MonoBehaviour
EmitImpactNoise(contactPoint);
}
public void ActivateHit(float duration)
{
_canHit = true;
if (_disableHitCoroutine != null)
StopCoroutine(_disableHitCoroutine);
_disableHitCoroutine = StartCoroutine(DisableHitAfter(duration));
}
private IEnumerator DisableHitAfter(float duration)
{
yield return new WaitForSeconds(duration);
_canHit = false;
_disableHitCoroutine = null;
}
private void HandleEnemyCollision(Character enemy, Vector2 impactVelocity)
{
// Apply stun to enemy
@@ -105,5 +128,11 @@ public class Hammer : MonoBehaviour
noiseSystem.Emit(position, _impactNoiseRadius);
}
}
private IEnumerator ResetCollisionCoroutine()
{
yield return new WaitForSeconds(0.25f);
_hasCollided = false;
}
}
+2 -2
View File
@@ -26,7 +26,7 @@ public class BreakableWall : MapElement
public override void Hit()
{
IsEnabled = false;
_boxCollider.isTrigger = true;
_boxCollider.enabled = false;
_spriteRenderer.enabled = IsEnabled;
Instantiate(_hitParticles, transform.position, Quaternion.identity);
@@ -55,7 +55,7 @@ public class BreakableWall : MapElement
print("Character is dead");
}
IsEnabled = true;
_boxCollider.isTrigger = false;
_boxCollider.enabled = true;
_spriteRenderer.enabled = IsEnabled;
_needRespawn = false;
}
+25 -25
View File
@@ -12,8 +12,8 @@ public abstract class Character : MonoBehaviour
[SerializeField]
private LayerMask _mapLayer;
private Rigidbody2D _body;
private CapsuleCollider2D _capsuleCollider;
private Rigidbody _body;
private CapsuleCollider _capsuleCollider;
protected bool _isOnBridge;
private bool _isOnLadder = false;
@@ -31,8 +31,8 @@ public abstract class Character : MonoBehaviour
public void Init()
{
_body = GetComponent<Rigidbody2D>();
_capsuleCollider = GetComponent<CapsuleCollider2D>();
_body = GetComponent<Rigidbody>();
_capsuleCollider = GetComponent<CapsuleCollider>();
_cellSize = new Vector2(0.6f, 1f);
}
@@ -98,11 +98,11 @@ public abstract class Character : MonoBehaviour
if (_isOnLadder || _isOnBridge)
{
_body.gravityScale = 0;
//_body.gravityScale = 0;
}
else
{
_body.gravityScale = 1;
//_body.gravityScale = 1;
}
if (_isFalling)
{
@@ -125,12 +125,12 @@ public abstract class Character : MonoBehaviour
private bool CanClimbUp()
{
var rayCastHit = Physics2D.Raycast(_capsuleCollider.bounds.center, Vector2.down, _capsuleCollider.size.y / 2,_mapLayer);
if(rayCastHit)
if(rayCastHit.collider.transform.GetComponent<MapElement>().ElementSO.ElementType==MapElementType.Ladder)
{
return true;
}
// var rayCastHit = Physics2D.Raycast(_capsuleCollider.bounds.center, Vector2.down, _capsuleCollider.size.y / 2,_mapLayer);
// if(rayCastHit)
// if(rayCastHit.collider.transform.GetComponent<MapElement>().ElementSO.ElementType==MapElementType.Ladder)
// {
// return true;
// }
return false;
}
@@ -153,20 +153,20 @@ public abstract class Character : MonoBehaviour
private MapElement GetMapElement()
{
var collider = BoxCast(_capsuleCollider.bounds.center, _cellSize, 0f, Vector3.forward, .01f, _mapLayer);
Color color = Color.red;
MapElement mapElement = null;
if (collider.Length > 0)
{
var elements=collider.Select(x=>x.transform.GetComponent<MapElement>());
mapElement = elements.Where(x => x.ElementSO.ElementType == MapElementType.Ladder).FirstOrDefault();
if(mapElement == null)
{
mapElement = elements.First();
}
}
var collider = BoxCast(_capsuleCollider.bounds.center, _cellSize, 0f, Vector3.forward, .01f, _mapLayer);
Color color = Color.red;
MapElement mapElement = null;
if (collider.Length > 0)
{
var elements=collider.Select(x=>x.transform.GetComponent<MapElement>());
mapElement = elements.Where(x => x.ElementSO.ElementType == MapElementType.Ladder).FirstOrDefault();
if(mapElement == null)
{
mapElement = elements.First();
}
}
return mapElement;
return mapElement;
}
protected abstract void SetWalkingAnimation(bool isWalking);