diff --git a/Assembly-CSharp-Editor.csproj b/Assembly-CSharp-Editor.csproj index 9d992aa..5c6e024 100644 --- a/Assembly-CSharp-Editor.csproj +++ b/Assembly-CSharp-Editor.csproj @@ -647,6 +647,9 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Rider.Editor.dll + + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.dll + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Psdimporter.Editor.dll @@ -671,6 +674,9 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Animation.Editor.dll + + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Common.Editor.dll @@ -679,12 +685,6 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/UnityEditor.UI.dll - - - /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.dll - - - /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index eea74b0..629f45b 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -634,6 +634,9 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Rider.Editor.dll + + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.dll + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Psdimporter.Editor.dll @@ -658,6 +661,9 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Animation.Editor.dll + + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll + /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.2D.Common.Editor.dll @@ -666,12 +672,6 @@ /D/Unity/Projects/Projekt/Library/ScriptAssemblies/UnityEditor.UI.dll - - - /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.dll - - - /D/Unity/Projects/Projekt/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 4280c2b..1da550a 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -720,7 +720,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1692511763} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.67, y: 2.4, z: -2.796909} + m_LocalPosition: {x: 2.27, y: 2.74, z: -2.796909} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -743,7 +743,7 @@ GameObject: - component: {fileID: 2053847427} m_Layer: 0 m_Name: Character - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/EnemyController.cs b/Assets/Scripts/EnemyController.cs index 51a40c1..c69b761 100644 --- a/Assets/Scripts/EnemyController.cs +++ b/Assets/Scripts/EnemyController.cs @@ -79,4 +79,13 @@ public class EnemyController : MonoBehaviour else HitWhileFlying(); } + + private void OnCollisionEnter2D(Collision2D other) + { + var go = other.gameObject; + if(!go.CompareTag("Player")) + return; + if (IsAlive()) + go.GetComponent().Hit(); + } } diff --git a/Assets/Scripts/EnemySpawner.cs b/Assets/Scripts/EnemySpawner.cs index ea545d7..1d3b4d5 100644 --- a/Assets/Scripts/EnemySpawner.cs +++ b/Assets/Scripts/EnemySpawner.cs @@ -28,7 +28,7 @@ public class EnemySpawner : MonoBehaviour for (int i = 0; i < count; i++) { var pos = transform.position + _diff; - var enemy = _pool.GetObject(); + var enemy = _pool.GetObject(true); if (enemy is null) break; enemy.transform.position = new Vector3(pos.x, spawnPos.position.y, pos.z); var rb = enemy.GetComponent(); diff --git a/Assets/Scripts/ObjectPool.cs b/Assets/Scripts/ObjectPool.cs index 4a6bfb3..716cf44 100644 --- a/Assets/Scripts/ObjectPool.cs +++ b/Assets/Scripts/ObjectPool.cs @@ -18,10 +18,9 @@ public class ObjectPool /// Visszaad egy új objektumot. Aktiválandó, használat után pedig deaktiválandó. /// /// Egy objektum a poolból. - public GameObject GetObject(short maxCount = 0) + public GameObject GetObject(bool fixedPool = false) { GameObject theRocket = null; - int c = 0; foreach (var rocket in _objects) { if (!rocket.activeSelf) @@ -29,14 +28,13 @@ public class ObjectPool theRocket = rocket; break; } - - c++; - if (c == maxCount) - return null; } if (theRocket is null) - _objects.Add(theRocket = Object.Instantiate(_prefab)); + if (fixedPool) + return null; + else + _objects.Add(theRocket = Object.Instantiate(_prefab)); return theRocket; } } \ No newline at end of file diff --git a/Assets/Scripts/OwnCharacterController.cs b/Assets/Scripts/OwnCharacterController.cs index 658c79f..f8fc915 100644 --- a/Assets/Scripts/OwnCharacterController.cs +++ b/Assets/Scripts/OwnCharacterController.cs @@ -1,28 +1,29 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class OwnCharacterController : MonoBehaviour { - private Rigidbody2D rb; - private Collider2D collider; + private Rigidbody2D _rb; + private Vector3 _spawnPos; // Start is called before the first frame update void Start() { - rb = GetComponent(); - collider = GetComponent(); + _rb = GetComponent(); + _spawnPos = transform.position; } // Update is called once per frame void Update() { - if (Mathf.Abs(rb.velocity.x) > 3) + if (Mathf.Abs(_rb.velocity.x) > 3) return; float input = Input.GetAxis("Horizontal"); - if (input < 0 && rb.transform.localScale.x > 0 - || input > 0 && rb.transform.localScale.x < 0) + if (input < 0 && _rb.transform.localScale.x > 0 + || input > 0 && _rb.transform.localScale.x < 0) { var tr = transform; var scale = tr.localScale; @@ -32,16 +33,26 @@ public class OwnCharacterController : MonoBehaviour if (Input.GetButton("Fire3")) input *= 10; - rb.AddForce(new Vector2(input * 5, 0)); + _rb.AddForce(new Vector2(input * 5, 0)); if (Input.GetButtonDown("Jump") && IsOnGround()) - rb.AddForce(new Vector2(0, 4), ForceMode2D.Impulse); + _rb.AddForce(new Vector2(0, 4), ForceMode2D.Impulse); + } + + public void Hit() + { + Respawn(); + } + + private void Respawn() + { + transform.position = _spawnPos; } private bool IsOnGround() { var res = new List(); - rb.OverlapCollider(new ContactFilter2D(), res); + _rb.OverlapCollider(new ContactFilter2D(), res); return res.Any(col => col.CompareTag("Ground")); } } \ No newline at end of file