added character spawner script, spawn and destroy characters

This commit is contained in:
2023-08-01 15:48:00 +00:00
parent ef90dd7872
commit ef2b90b8b7
9 changed files with 306 additions and 660 deletions
+8 -14
View File
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using UnityEngine;
public abstract class Character : MonoBehaviour
@@ -11,13 +12,11 @@ public abstract class Character : MonoBehaviour
protected GameObject _bonesSide;
[SerializeField]
protected GameObject _bonesBack;
[SerializeField]
protected GameObject _spawnPoint;
[SerializeField]
private LayerMask _mapLayer;
protected SpriteRenderer _spriteRenderer;
@@ -36,20 +35,16 @@ public abstract class Character : MonoBehaviour
protected bool isAllowLeft = true;
private Vector2 _cellSize;
public event EventHandler OnCharacterDeath;
private void Start()
{
_body = GetComponent<Rigidbody2D>();
_capsuleCollider = GetComponent<CapsuleCollider2D>();
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
_cellSize = new Vector2(0.6f, 1f);
Spawn();
_cellSize = new Vector2(0.6f, 1f);
}
protected void Spawn()
{
transform.position = _spawnPoint.transform.position;
}
protected void MoveTo(float inputHorizontal, float inputVertical)
{
var block = GetMapElement();
@@ -132,9 +127,9 @@ public abstract class Character : MonoBehaviour
}
private void Death()
protected void Death()
{
OnDeath();
OnCharacterDeath?.Invoke(this,EventArgs.Empty);
}
private bool CanClimbUp()
@@ -174,7 +169,6 @@ public abstract class Character : MonoBehaviour
return mapElement;
}
protected abstract void OnDeath();
protected abstract void SetWalkingAnimation(bool isWalking);
protected abstract void SetClimbingAnimation(bool isClimbing);