added character spawner script, spawn and destroy characters
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user