From 286e0a0b24939c2c75f46e043c92a7bd7e8d12f4 Mon Sep 17 00:00:00 2001 From: Mingu Kim Date: Thu, 7 Aug 2025 20:51:14 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=B4=EC=8A=A4=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EC=B6=94=EA=B0=80(=EB=9E=9C=EB=8D=A4=20?= =?UTF-8?q?=EC=A2=8C=EC=9A=B0=EC=9D=B4=EB=8F=99,=20=EB=82=AD=EB=96=A0?= =?UTF-8?q?=EB=9F=AC=EC=A7=80=20=EC=B2=B4=ED=81=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/SampleScene.unity | 37 ++++----- Assets/Scripts/Enemies/BossEnemyMove.cs | 79 ++++++++++++++++++++ Assets/Scripts/Enemies/BossEnemyMove.cs.meta | 2 + 3 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 Assets/Scripts/Enemies/BossEnemyMove.cs create mode 100644 Assets/Scripts/Enemies/BossEnemyMove.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 160a52c1..a41d9bf2 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -644,7 +644,7 @@ GameObject: - component: {fileID: 114042779} - component: {fileID: 114042778} - component: {fileID: 114042777} - - component: {fileID: 114042776} + - component: {fileID: 114042780} m_Layer: 9 m_Name: False Knight m_TagString: Enemy @@ -652,18 +652,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!114 &114042776 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 114042775} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 0de3500b3118bd04ebf644b811d74319, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!70 &114042777 CapsuleCollider2D: m_ObjectHideFlags: 0 @@ -698,8 +686,8 @@ CapsuleCollider2D: m_UsedByEffector: 0 m_CompositeOperation: 0 m_CompositeOrder: 0 - m_Offset: {x: 0, y: 0.18} - m_Size: {x: 1.1, y: 1.03} + m_Offset: {x: 0, y: 0} + m_Size: {x: 4.11, y: 0.0001} m_Direction: 0 --- !u!50 &114042778 Rigidbody2D: @@ -737,13 +725,26 @@ Transform: m_GameObject: {fileID: 114042775} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 10.09, y: 0.76, z: 0} + m_LocalPosition: {x: -11.15, y: 2.55, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 268751596} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &114042780 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 114042775} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 69b79b76424d246f4b6e65cea814d386, type: 3} + m_Name: + m_EditorClassIdentifier: + nextMove: 0 --- !u!1 &119726257 GameObject: m_ObjectHideFlags: 0 @@ -1972,7 +1973,7 @@ Transform: m_GameObject: {fileID: 268751595} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 7.59, y: 2.32, z: 0} + m_LocalPosition: {x: 0.12, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -2791,7 +2792,7 @@ Transform: m_GameObject: {fileID: 442352395} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 4.408833, y: 3.880091, z: 0} + m_LocalPosition: {x: 13.91, y: 7.58, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Scripts/Enemies/BossEnemyMove.cs b/Assets/Scripts/Enemies/BossEnemyMove.cs new file mode 100644 index 00000000..a8f2b8af --- /dev/null +++ b/Assets/Scripts/Enemies/BossEnemyMove.cs @@ -0,0 +1,79 @@ +using UnityEngine; + +public class BossEnemyMove : MonoBehaviour +{ + // Start is called once before the first execution of Update after the MonoBehaviour is created + Rigidbody2D _rigidbody; + public int nextMove; + private SpriteRenderer _childSpriteRenderer; + + void Start() + { + // 자식 오브젝트 찾기 + Transform childTransform = transform.Find("Renderer"); + + if (childTransform != null) + { + // 자식 오브젝트에서 스프라이트 렌더러 컴포넌트 가져오기 + _childSpriteRenderer = childTransform.GetComponent(); + + if (_childSpriteRenderer != null) + { + Debug.Log("자식 스프라이트 렌더러 찾음: " + _childSpriteRenderer.name); + } + else + { + Debug.LogWarning("자식 오브젝트에 스프라이트 렌더러 컴포넌트가 없습니다: "); + } + } + else + { + Debug.LogError("자식 오브젝트를 찾을 수 없습니다: "); + } + } + + void Awake() + { + _rigidbody = GetComponent(); + + Invoke("Think", 5f); // 5초 후에 다시 생각 시작 + } + + private void FixedUpdate() + { + // 스프라이트 방향 이동 방향에 맞도록 좌우 플립 + if (nextMove == 1) + { + _childSpriteRenderer.flipX = false; + } + else + { + _childSpriteRenderer.flipX = true; + } + + // 이동 + _rigidbody.linearVelocity = new Vector2(nextMove, _rigidbody.linearVelocityY); + + // 지형 체크 (떨어짐 방지) + Vector2 frontVec = new Vector2(_rigidbody.position.x + nextMove, _rigidbody.position.y); + + Debug.DrawRay(frontVec, Vector3.down, Color.green); + + RaycastHit2D rayHit = Physics2D.Raycast(frontVec, Vector3.down, 5, LayerMask.GetMask("Platform")); + + // 낭떠러지 체크 + if(rayHit.collider == null) + { + Debug.Log("낭떠러지!"); + } + } + + // 생각 반복 재귀 + void Think() + { + // random 값 범위 = -1, 0, 1 + nextMove = Random.Range(-1, 2); + + Invoke("Think", 5f); // 5초 후에 다시 생각 시작 + } +} diff --git a/Assets/Scripts/Enemies/BossEnemyMove.cs.meta b/Assets/Scripts/Enemies/BossEnemyMove.cs.meta new file mode 100644 index 00000000..02038f7d --- /dev/null +++ b/Assets/Scripts/Enemies/BossEnemyMove.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 69b79b76424d246f4b6e65cea814d386 \ No newline at end of file