add spawn point, death

This commit is contained in:
2023-07-10 19:21:58 +03:00
parent 9d68af5244
commit 2df859debe
9 changed files with 163 additions and 7 deletions
+21
View File
@@ -1,3 +1,4 @@
using System;
using UnityEngine;
public abstract class Character : MonoBehaviour
@@ -10,6 +11,9 @@ public abstract class Character : MonoBehaviour
protected GameObject _bonesSide;
[SerializeField]
protected GameObject _bonesBack;
[SerializeField]
protected GameObject _spawnPoint;
[SerializeField]
private LayerMask _mapLayer;
@@ -34,10 +38,20 @@ public abstract class Character : MonoBehaviour
_capsuleCollider = GetComponent<CapsuleCollider2D>();
}
protected void Spawn()
{
transform.position=_spawnPoint.transform.position;
}
protected void MoveTo(float inputHorizontal, float inputVertical)
{
var mapElement = GetMapElement(Vector2.down);
if(mapElement==MapElementType.Water)
{
Death();
}
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
@@ -103,6 +117,12 @@ public abstract class Character : MonoBehaviour
}
private void Death()
{
OnDeath();
}
private MapElementType GetMapElement(Vector2 direction)
{
Vector2 rayStartPoint;
@@ -137,6 +157,7 @@ public abstract class Character : MonoBehaviour
return returnValue;
}
protected abstract void OnDeath();
protected abstract void SetWalkingAnimation(bool isWalking);
protected abstract void SetClimbingAnimation(bool isClimbing);
+5
View File
@@ -2,6 +2,11 @@ using UnityEngine;
public class EnemyAI : Character
{
protected override void OnDeath()
{
throw new System.NotImplementedException();
}
protected override void SetClimbingAnimation(bool isClimbing)
{
}
+1 -6
View File
@@ -11,15 +11,10 @@ public class Hammer : MonoBehaviour
private void OnCollisionEnter2D(Collision2D collision)
{
var mapElement = collision.collider.GetComponent<MapElement>();
if(mapElement!=null)
{
Destroy(gameObject);
}
if (mapElement?.ElementSO.ElementType==MapElementType.BreakableWall)
if (mapElement != null)
{
mapElement.Hit();
Destroy(gameObject);
}
}
}
+15
View File
@@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 541209b3a8828a3429d3a6c93b0350f3, type: 3}
m_Name: Water
m_EditorClassIdentifier:
ElementType: 5
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 59cbe601225090b41a19270c63bc6390
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
+16 -1
View File
@@ -12,6 +12,8 @@ public class Player : Character
[SerializeField]
private Sprite _noHammerSprite;
public int Lives=3;
private int _hammerSpeed = 5;
private int _totalCoins = 0;
@@ -25,7 +27,6 @@ public class Player : Character
private void Awake()
{
if (Instance != null)
{
Destroy(gameObject);
@@ -37,6 +38,7 @@ public class Player : Character
DontDestroyOnLoad(gameObject);
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
Spawn();
}
public void AddCoin()
@@ -105,4 +107,17 @@ public class Player : Character
}
_animator.SetBool("Climb", isClimbing);
}
protected override void OnDeath()
{
Lives--;
Spawn();
if (Lives==0)
{
print("game over");
}
}
}