diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index c318dce..22b086e 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -5069,6 +5069,7 @@ GameObject: m_Component: - component: {fileID: 874939978} - component: {fileID: 874939979} + - component: {fileID: 874939980} m_Layer: 0 m_Name: ObstacleSafe m_TagString: Untagged @@ -5121,7 +5122,7 @@ BoxCollider2D: m_CallbackLayers: serializedVersion: 2 m_Bits: 4294967295 - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_CompositeOperation: 0 m_CompositeOrder: 0 @@ -5137,6 +5138,20 @@ BoxCollider2D: m_AutoTiling: 0 m_Size: {x: 5.068964, y: 5.1134825} m_EdgeRadius: 0 +--- !u!114 &874939980 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 874939977} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 982954923c829c546bed40ee7f6b946a, type: 3} + m_Name: + m_EditorClassIdentifier: + playerScript: {fileID: 0} + playerObject: {fileID: 1267397455} --- !u!1 &1009490386 GameObject: m_ObjectHideFlags: 0 @@ -5495,6 +5510,7 @@ MonoBehaviour: initialPosition: {x: 0, y: 0, z: 0} initialRotation: {x: 0, y: 0, z: 0, w: 0} particle: {fileID: 725779776} + isColliding: 1 --- !u!61 &1267397460 BoxCollider2D: m_ObjectHideFlags: 0 @@ -5862,7 +5878,7 @@ GameObject: m_Component: - component: {fileID: 1914709940} - component: {fileID: 1914709942} - - component: {fileID: 1914709941} + - component: {fileID: 1914709943} m_Layer: 0 m_Name: ObstacleKiller m_TagString: Untagged @@ -5885,20 +5901,6 @@ Transform: m_Children: [] m_Father: {fileID: 1009490389} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1914709941 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1914709939} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e105dbba5bf85a944a8270ed72ebd3d2, type: 3} - m_Name: - m_EditorClassIdentifier: - playerScript: {fileID: 0} - playerObject: {fileID: 1267397455} --- !u!61 &1914709942 BoxCollider2D: m_ObjectHideFlags: 0 @@ -5945,6 +5947,20 @@ BoxCollider2D: m_AutoTiling: 0 m_Size: {x: 5.0600605, y: 3.5822077} m_EdgeRadius: 0 +--- !u!114 &1914709943 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1914709939} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4ad4baca6c852a00b8bf21afdd5fba8c, type: 3} + m_Name: + m_EditorClassIdentifier: + playerScript: {fileID: 0} + playerObject: {fileID: 1267397455} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Obstacle.cs.meta b/Assets/Scripts/Obstacle.cs.meta deleted file mode 100644 index 216815a..0000000 --- a/Assets/Scripts/Obstacle.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: e105dbba5bf85a944a8270ed72ebd3d2 \ No newline at end of file diff --git a/Assets/Scripts/Obstacle.cs b/Assets/Scripts/ObstacleKiller.cs similarity index 84% rename from Assets/Scripts/Obstacle.cs rename to Assets/Scripts/ObstacleKiller.cs index 16c0528..6975949 100644 --- a/Assets/Scripts/Obstacle.cs +++ b/Assets/Scripts/ObstacleKiller.cs @@ -1,6 +1,6 @@ using UnityEngine; -public class Obstacle : MonoBehaviour +public class ObstacleKiller : MonoBehaviour { public PlayerScript playerScript; public GameObject playerObject; @@ -19,5 +19,6 @@ public class Obstacle : MonoBehaviour { playerObject.transform.rotation = playerScript.initialRotation; playerObject.transform.position = playerScript.initialPosition; + playerScript.isColliding = false; } } diff --git a/Assets/Scripts/ObstacleKiller.cs.meta b/Assets/Scripts/ObstacleKiller.cs.meta new file mode 100644 index 0000000..d03c040 --- /dev/null +++ b/Assets/Scripts/ObstacleKiller.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 4ad4baca6c852a00b8bf21afdd5fba8c \ No newline at end of file diff --git a/Assets/Scripts/ObstacleSafe.cs b/Assets/Scripts/ObstacleSafe.cs new file mode 100644 index 0000000..11fcda7 --- /dev/null +++ b/Assets/Scripts/ObstacleSafe.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +public class ObstacleSafe : MonoBehaviour +{ + public PlayerScript playerScript; + public GameObject playerObject; + + public void Start() + { + playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent(); + } + + public void Update() + { + + } + + public void OnCollisionEnter() + { + playerScript.isColliding = true; + } + + public void OnCollisionExit() + { + playerScript.isColliding = false; + } +} diff --git a/Assets/Scripts/ObstacleSafe.cs.meta b/Assets/Scripts/ObstacleSafe.cs.meta new file mode 100644 index 0000000..0ed8814 --- /dev/null +++ b/Assets/Scripts/ObstacleSafe.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 982954923c829c546bed40ee7f6b946a \ No newline at end of file diff --git a/Assets/Scripts/PlayerScript.cs b/Assets/Scripts/PlayerScript.cs index ec3bbb0..1d72aa3 100644 --- a/Assets/Scripts/PlayerScript.cs +++ b/Assets/Scripts/PlayerScript.cs @@ -11,6 +11,7 @@ public class PlayerScript : MonoBehaviour public ParticleSystem particle; private bool wantsToJump = false; + public bool isColliding = true; public void Start() { @@ -66,7 +67,8 @@ public class PlayerScript : MonoBehaviour private bool IsJumping() { - return Mathf.Abs(initialPosition.y - transform.position.y) > 0.05f; + // return Mathf.Abs(initialPosition.y - transform.position.y) > 0.05f; + return !isColliding; } private void AlignRotation() diff --git a/Assets/Scripts/SpikeScript.cs b/Assets/Scripts/SpikeScript.cs index 8198ae0..3a77efd 100644 --- a/Assets/Scripts/SpikeScript.cs +++ b/Assets/Scripts/SpikeScript.cs @@ -19,5 +19,6 @@ public class SpikeScript : MonoBehaviour { playerObject.transform.rotation = playerScript.initialRotation; playerObject.transform.position = playerScript.initialPosition; + playerScript.isColliding = false; } }