add spawn point, death
This commit is contained in:
@@ -2659,6 +2659,37 @@ Transform:
|
|||||||
m_Father: {fileID: 1123299336}
|
m_Father: {fileID: 1123299336}
|
||||||
m_RootOrder: -1
|
m_RootOrder: -1
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!1 &461379296
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 461379297}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: PlayerSpawnPoint
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &461379297
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 461379296}
|
||||||
|
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||||
|
m_LocalPosition: {x: -8.54, y: 3.32, z: -0.06965188}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1173618893}
|
||||||
|
m_RootOrder: -1
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &489846349
|
--- !u!1001 &489846349
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -2755,6 +2786,7 @@ MonoBehaviour:
|
|||||||
MovementSpeed: 2
|
MovementSpeed: 2
|
||||||
_bonesSide: {fileID: 0}
|
_bonesSide: {fileID: 0}
|
||||||
_bonesBack: {fileID: 0}
|
_bonesBack: {fileID: 0}
|
||||||
|
_spawnPoint: {fileID: 0}
|
||||||
_mapLayer:
|
_mapLayer:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 8
|
m_Bits: 8
|
||||||
@@ -3588,6 +3620,8 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 923801478}
|
- component: {fileID: 923801478}
|
||||||
- component: {fileID: 923801477}
|
- component: {fileID: 923801477}
|
||||||
|
- component: {fileID: 923801479}
|
||||||
|
- component: {fileID: 923801480}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Water
|
m_Name: Water
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -3662,6 +3696,64 @@ Transform:
|
|||||||
m_Father: {fileID: 1173618893}
|
m_Father: {fileID: 1173618893}
|
||||||
m_RootOrder: -1
|
m_RootOrder: -1
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!61 &923801479
|
||||||
|
BoxCollider2D:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 923801476}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_Density: 1
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IncludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_ExcludeLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
|
m_LayerOverridePriority: 0
|
||||||
|
m_ForceSendLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_ForceReceiveLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_ContactCaptureLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_CallbackLayers:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 4294967295
|
||||||
|
m_IsTrigger: 1
|
||||||
|
m_UsedByEffector: 0
|
||||||
|
m_UsedByComposite: 0
|
||||||
|
m_Offset: {x: 0, y: 0}
|
||||||
|
m_SpriteTilingProperty:
|
||||||
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
pivot: {x: 0.5, y: 0.5}
|
||||||
|
oldSize: {x: 1, y: 1}
|
||||||
|
newSize: {x: 1, y: 1}
|
||||||
|
adaptiveTilingThreshold: 0.5
|
||||||
|
drawMode: 0
|
||||||
|
adaptiveTiling: 0
|
||||||
|
m_AutoTiling: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Size: {x: 1, y: 1}
|
||||||
|
m_EdgeRadius: 0
|
||||||
|
--- !u!114 &923801480
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 923801476}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: edf40d39eadb17a4ebb0368b3ac5399a, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
_elementSO: {fileID: 11400000, guid: 59cbe601225090b41a19270c63bc6390, type: 2}
|
||||||
--- !u!1001 &975611551
|
--- !u!1001 &975611551
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -3979,6 +4071,7 @@ Transform:
|
|||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
|
- {fileID: 461379297}
|
||||||
- {fileID: 923801478}
|
- {fileID: 923801478}
|
||||||
- {fileID: 679297304}
|
- {fileID: 679297304}
|
||||||
- {fileID: 2012902680}
|
- {fileID: 2012902680}
|
||||||
@@ -5964,6 +6057,10 @@ PrefabInstance:
|
|||||||
propertyPath: _bonesSide
|
propertyPath: _bonesSide
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 582706328}
|
objectReference: {fileID: 582706328}
|
||||||
|
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
||||||
|
propertyPath: _spawnPoint
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 461379296}
|
||||||
- target: {fileID: 3156624200786225141, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
- target: {fileID: 3156624200786225141, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
||||||
propertyPath: m_Layer
|
propertyPath: m_Layer
|
||||||
value: 8
|
value: 8
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public abstract class Character : MonoBehaviour
|
public abstract class Character : MonoBehaviour
|
||||||
@@ -10,6 +11,9 @@ public abstract class Character : MonoBehaviour
|
|||||||
protected GameObject _bonesSide;
|
protected GameObject _bonesSide;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected GameObject _bonesBack;
|
protected GameObject _bonesBack;
|
||||||
|
[SerializeField]
|
||||||
|
protected GameObject _spawnPoint;
|
||||||
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private LayerMask _mapLayer;
|
private LayerMask _mapLayer;
|
||||||
@@ -34,10 +38,20 @@ public abstract class Character : MonoBehaviour
|
|||||||
_capsuleCollider = GetComponent<CapsuleCollider2D>();
|
_capsuleCollider = GetComponent<CapsuleCollider2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void Spawn()
|
||||||
|
{
|
||||||
|
transform.position=_spawnPoint.transform.position;
|
||||||
|
}
|
||||||
|
|
||||||
protected void MoveTo(float inputHorizontal, float inputVertical)
|
protected void MoveTo(float inputHorizontal, float inputVertical)
|
||||||
{
|
{
|
||||||
var mapElement = GetMapElement(Vector2.down);
|
var mapElement = GetMapElement(Vector2.down);
|
||||||
|
|
||||||
|
if(mapElement==MapElementType.Water)
|
||||||
|
{
|
||||||
|
Death();
|
||||||
|
}
|
||||||
|
|
||||||
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
||||||
|
|
||||||
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
|
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)
|
private MapElementType GetMapElement(Vector2 direction)
|
||||||
{
|
{
|
||||||
Vector2 rayStartPoint;
|
Vector2 rayStartPoint;
|
||||||
@@ -137,6 +157,7 @@ public abstract class Character : MonoBehaviour
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void OnDeath();
|
||||||
protected abstract void SetWalkingAnimation(bool isWalking);
|
protected abstract void SetWalkingAnimation(bool isWalking);
|
||||||
protected abstract void SetClimbingAnimation(bool isClimbing);
|
protected abstract void SetClimbingAnimation(bool isClimbing);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class EnemyAI : Character
|
public class EnemyAI : Character
|
||||||
{
|
{
|
||||||
|
protected override void OnDeath()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
protected override void SetClimbingAnimation(bool isClimbing)
|
protected override void SetClimbingAnimation(bool isClimbing)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,10 @@ public class Hammer : MonoBehaviour
|
|||||||
private void OnCollisionEnter2D(Collision2D collision)
|
private void OnCollisionEnter2D(Collision2D collision)
|
||||||
{
|
{
|
||||||
var mapElement = collision.collider.GetComponent<MapElement>();
|
var mapElement = collision.collider.GetComponent<MapElement>();
|
||||||
if(mapElement!=null)
|
if (mapElement != null)
|
||||||
{
|
|
||||||
Destroy(gameObject);
|
|
||||||
}
|
|
||||||
if (mapElement?.ElementSO.ElementType==MapElementType.BreakableWall)
|
|
||||||
{
|
{
|
||||||
mapElement.Hit();
|
mapElement.Hit();
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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:
|
||||||
@@ -12,6 +12,8 @@ public class Player : Character
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Sprite _noHammerSprite;
|
private Sprite _noHammerSprite;
|
||||||
|
|
||||||
|
public int Lives=3;
|
||||||
|
|
||||||
private int _hammerSpeed = 5;
|
private int _hammerSpeed = 5;
|
||||||
|
|
||||||
private int _totalCoins = 0;
|
private int _totalCoins = 0;
|
||||||
@@ -25,7 +27,6 @@ public class Player : Character
|
|||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Instance != null)
|
if (Instance != null)
|
||||||
{
|
{
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
@@ -37,6 +38,7 @@ public class Player : Character
|
|||||||
DontDestroyOnLoad(gameObject);
|
DontDestroyOnLoad(gameObject);
|
||||||
|
|
||||||
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
||||||
|
Spawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCoin()
|
public void AddCoin()
|
||||||
@@ -105,4 +107,17 @@ public class Player : Character
|
|||||||
}
|
}
|
||||||
_animator.SetBool("Climb", isClimbing);
|
_animator.SetBool("Climb", isClimbing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnDeath()
|
||||||
|
{
|
||||||
|
Lives--;
|
||||||
|
Spawn();
|
||||||
|
|
||||||
|
if (Lives==0)
|
||||||
|
{
|
||||||
|
print("game over");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user