implementing goblin death, need to find way deactivate it for time

This commit is contained in:
2023-07-26 23:12:52 +03:00
parent acdd8b7d16
commit 9085da5e23
6 changed files with 536 additions and 400 deletions
+11 -3
View File
@@ -26,6 +26,7 @@ public abstract class Character : MonoBehaviour
protected bool _isFalling;
protected bool _facingRight = true;
protected bool isCanGoDown = false;
protected bool isCanClimbUp=false;
protected bool isAllowVertical = true;
protected bool isAllowRight = true;
@@ -38,6 +39,7 @@ public abstract class Character : MonoBehaviour
_capsuleCollider = GetComponent<CapsuleCollider2D>();
_cellSize = new Vector2(0.6f, 1f);
Spawn();
}
protected void Spawn()
@@ -74,7 +76,7 @@ public abstract class Character : MonoBehaviour
if (_isOnLadder)
{
isCanClimbUp=CanClimbUp();
isCanGoDown = CanGoDown();
float ladderXCenterDistance = Mathf.Abs(transform.position.x - block.transform.position.x);
float v_movement = inputVertical;
@@ -143,10 +145,16 @@ public abstract class Character : MonoBehaviour
return false;
}
private bool CanGoDown()
{
var rayCastHit = Physics2D.RaycastAll(_capsuleCollider.bounds.center, Vector2.down, _capsuleCollider.size.y+0.5f, _mapLayer);
if (rayCastHit.Any(x=>x.collider.transform.GetComponent<MapElement>().ElementSO.ElementType != MapElementType.Ladder))
return false;
return true;
}
private MapElement GetMapElement()
{
var collider = BoxCast(_capsuleCollider.bounds.center, _cellSize, 0f, Vector3.forward, .01f, _mapLayer);
Color color = Color.red;
MapElement mapElement = null;
+37 -18
View File
@@ -1,11 +1,15 @@
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine;
public class EnemyAI : Character
{
private bool _needRespawn = false;
private int _respawnTimeout = 4;
private float _respawnElementTimer;
protected override void OnDeath()
{
}
_needRespawn = true;
}
protected override void SetClimbingAnimation(bool isClimbing)
{
@@ -17,35 +21,50 @@ public class EnemyAI : Character
private void Update()
{
if(_needRespawn)
{
_respawnElementTimer -= Time.deltaTime;
if (_respawnElementTimer <= 0)
{
_respawnElementTimer = _respawnTimeout;
_needRespawn = false;
Spawn();
}
return;
}
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)
if (verticalDistance > 0 && isCanClimbUp && isAllowVertical)
{
horizontal = directionToPlayer.x;
vertical = VerticalMove(verticalDistance);
}
else if (verticalDistance>0 && isCanClimbUp && isAllowVertical)
else if (verticalDistance < 0 && isAllowVertical && isCanGoDown)
{
vertical =VerticalMove(verticalDistance);
}
else if (verticalDistance<0 && isAllowVertical)
{
vertical =VerticalMove(verticalDistance);
vertical = VerticalMove(verticalDistance);
}
else
{
horizontal = directionToPlayer.x;
}
if (Mathf.Abs(Player.Instance.transform.position.x - transform.position.x) < 0.1f)
{
print($"horizontal block");
horizontal = 0;
}
else if (directionToPlayer.x < 0)
{ horizontal = -1; }
else if (directionToPlayer.x > 0)
{ horizontal = 1; }
}
print($"horizontal {horizontal}");
if (Input.GetKey(KeyCode.F))
{ horizontal = -1; }
if (Input.GetKey(KeyCode.H))
{ horizontal = 1; }
if (Input.GetKey(KeyCode.T))
{ vertical = 1; }
if (Input.GetKey(KeyCode.G))
+4 -3
View File
@@ -15,7 +15,8 @@ public class BreakableWall : MapElement
private void Start()
{
_boxCollider=GetComponent<BoxCollider2D>();
_respawnElementTimer = _respawnTimeout;
_boxCollider =GetComponent<BoxCollider2D>();
_spriteRenderer= GetComponentInChildren<SpriteRenderer>();
}
@@ -23,7 +24,7 @@ public class BreakableWall : MapElement
{
IsEnabled = false;
_boxCollider.isTrigger=true;
_spriteRenderer.enabled = false;
_spriteRenderer.enabled = IsEnabled;
Instantiate(_hitParticles, transform.position, Quaternion.identity);
@@ -46,7 +47,7 @@ public class BreakableWall : MapElement
}
IsEnabled = true;
_boxCollider.isTrigger = false;
_spriteRenderer.enabled = true;
_spriteRenderer.enabled = IsEnabled;
_needRespawn = false;
}
}
-1
View File
@@ -47,7 +47,6 @@ public class Player : Character
DontDestroyOnLoad(gameObject);
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
Spawn();
}
public void AddCoin()