From 536d777d5f0bd96b8ddb904e77a8f48af3b9a02a Mon Sep 17 00:00:00 2001 From: slevy14 Date: Wed, 26 Apr 2023 16:52:49 -0700 Subject: [PATCH] player can now jump on enemies to defeat them --- Assets/Prefabs/Projectile.prefab | 2 +- Assets/Prefabs/Snake.prefab | 2 +- Assets/Scenes/GrappleScene.unity | 73 ++++++++++++++++++++++++++++++++ Assets/Scripts/PlayerBehavior.cs | 19 +++++++-- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/Assets/Prefabs/Projectile.prefab b/Assets/Prefabs/Projectile.prefab index 4dd391d..f40d9a3 100644 --- a/Assets/Prefabs/Projectile.prefab +++ b/Assets/Prefabs/Projectile.prefab @@ -193,7 +193,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 - m_Size: {x: 1, y: 1} + m_Size: {x: 5.5, y: 5.5} m_EdgeRadius: 0 --- !u!114 &217851877528699149 MonoBehaviour: diff --git a/Assets/Prefabs/Snake.prefab b/Assets/Prefabs/Snake.prefab index 1e5bb59..727ad2d 100644 --- a/Assets/Prefabs/Snake.prefab +++ b/Assets/Prefabs/Snake.prefab @@ -33,7 +33,7 @@ Transform: m_ConstrainProportionsScale: 1 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 14 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &493245979038171999 SpriteRenderer: diff --git a/Assets/Scenes/GrappleScene.unity b/Assets/Scenes/GrappleScene.unity index 63ded86..8b8632a 100644 --- a/Assets/Scenes/GrappleScene.unity +++ b/Assets/Scenes/GrappleScene.unity @@ -2042,6 +2042,79 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!1001 &1044872105 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_RootOrder + value: 18 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalScale.x + value: 0.4967 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalScale.y + value: 0.4967 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalScale.z + value: 0.4967 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalPosition.x + value: -31.1516 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalPosition.y + value: -10.7202 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171992, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 493245979038171997, guid: d175e4c5882b2464ab0425220d00a671, type: 3} + propertyPath: m_Name + value: Snake (1) + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: d175e4c5882b2464ab0425220d00a671, type: 3} --- !u!1 &1061595775 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 8b0aef3..8dec99c 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -150,8 +150,7 @@ public class PlayerBehavior : MonoBehaviour } else if (col.tag == "instaDeath") { - this.stateController.SetDeathCanvasActive(true); - Destroy(this.gameObject); + DestroyPlayer(); } else if (col.tag == "spawnPoint") { stateController.spawnPoint.GetComponent().DeactivateSpawnPoint(); @@ -169,8 +168,20 @@ public class PlayerBehavior : MonoBehaviour void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy") { - this.stateController.SetDeathCanvasActive(true); - Destroy(this.gameObject); + if (collision.transform.position.y < transform.position.y) { + Destroy(collision.gameObject); + } else { + DestroyPlayer(); + } + } + else if (collision.gameObject.tag == "Projectile") { + Destroy(collision.gameObject); + DestroyPlayer(); } } + + public void DestroyPlayer() { + this.stateController.SetDeathCanvasActive(true); + Destroy(this.gameObject); + } }