코드 리펙토링

This commit is contained in:
정세윤_crow 2026-01-23 19:22:52 +09:00
parent 79d947d176
commit 8e46b58e61
11 changed files with 423 additions and 260 deletions

View File

@ -72,7 +72,7 @@
"name": "", "name": "",
"id": "27687542-09ec-47b5-8f6c-5c672da72b21", "id": "27687542-09ec-47b5-8f6c-5c672da72b21",
"path": "<Keyboard>/space", "path": "<Keyboard>/space",
"interactions": "Press(pressPoint=1.401298E-45,behavior=2)", "interactions": "",
"processors": "", "processors": "",
"groups": "", "groups": "",
"action": "Jump", "action": "Jump",

View File

@ -105,7 +105,6 @@ GameObject:
- component: {fileID: 2556996269222904179} - component: {fileID: 2556996269222904179}
- component: {fileID: 6376878406717916855} - component: {fileID: 6376878406717916855}
- component: {fileID: 4035999004062947863} - component: {fileID: 4035999004062947863}
- component: {fileID: 1888074432508430436}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Player
@ -294,32 +293,3 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: eae62c41ce858ce478f29843ba0d3dea, type: 3} m_Script: {fileID: 11500000, guid: eae62c41ce858ce478f29843ba0d3dea, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::PlayerController m_EditorClassIdentifier: Assembly-CSharp::PlayerController
moveSpeed: 9
jumpSpeed: 18.2
jumpCutMultiplier: 0.3
minJumpDuration: 0.1
dashTime: 0.1
dashDistance: 5
enemyLayer:
serializedVersion: 2
m_Bits: 64
attackBoxSize: {x: 3, y: 1}
--- !u!114 &1888074432508430436
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 9138407101546400895}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3eada057783728046bc1f3df10f17294, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Entity
OnDeath:
m_PersistentCalls:
m_Calls: []
OnTakeDamage:
m_PersistentCalls:
m_Calls: []
data: {fileID: 0}

View File

@ -181,7 +181,10 @@ PrefabInstance:
- targetCorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3} - targetCorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
insertIndex: -1 insertIndex: -1
addedObject: {fileID: 519420032} addedObject: {fileID: 519420032}
m_AddedComponents: [] m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 9138407101546400895, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
insertIndex: -1
addedObject: {fileID: 1052407373}
m_SourcePrefab: {fileID: 100100000, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3} m_SourcePrefab: {fileID: 100100000, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
--- !u!1 &435424068 --- !u!1 &435424068
GameObject: GameObject:
@ -365,6 +368,11 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 1052407366} m_Father: {fileID: 1052407366}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &557650576 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 9138407101546400895, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
m_PrefabInstance: {fileID: 91367892}
m_PrefabAsset: {fileID: 0}
--- !u!1 &619394800 --- !u!1 &619394800
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1248,6 +1256,26 @@ Tilemap:
m_TileObjectToInstantiateIndex: 65535 m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0 dummyAlignment: 0
m_AllTileFlags: 1073741825 m_AllTileFlags: 1073741825
- first: {x: 1, y: -2, z: 0}
second:
serializedVersion: 2
m_TileIndex: 0
m_TileSpriteIndex: 0
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: 2, y: -2, z: 0}
second:
serializedVersion: 2
m_TileIndex: 0
m_TileSpriteIndex: 0
m_TileMatrixIndex: 0
m_TileColorIndex: 0
m_TileObjectToInstantiateIndex: 65535
dummyAlignment: 0
m_AllTileFlags: 1073741825
- first: {x: 3, y: -2, z: 0} - first: {x: 3, y: -2, z: 0}
second: second:
serializedVersion: 2 serializedVersion: 2
@ -1430,17 +1458,17 @@ Tilemap:
m_AllTileFlags: 1073741825 m_AllTileFlags: 1073741825
m_AnimatedTiles: {} m_AnimatedTiles: {}
m_TileAssetArray: m_TileAssetArray:
- m_RefCount: 88 - m_RefCount: 90
m_Data: {fileID: 11400000, guid: 8309c65724c3a8e40884dda0cfb55bae, type: 2} m_Data: {fileID: 11400000, guid: 8309c65724c3a8e40884dda0cfb55bae, type: 2}
- m_RefCount: 0 - m_RefCount: 0
m_Data: {fileID: 0} m_Data: {fileID: 0}
m_TileSpriteArray: m_TileSpriteArray:
- m_RefCount: 88 - m_RefCount: 90
m_Data: {fileID: -855298285791758126, guid: 9fc32b26c4b0b87459965e872a8507d2, type: 3} m_Data: {fileID: -855298285791758126, guid: 9fc32b26c4b0b87459965e872a8507d2, type: 3}
- m_RefCount: 0 - m_RefCount: 0
m_Data: {fileID: 0} m_Data: {fileID: 0}
m_TileMatrixArray: m_TileMatrixArray:
- m_RefCount: 88 - m_RefCount: 90
m_Data: m_Data:
e00: 1 e00: 1
e01: 0 e01: 0
@ -1459,7 +1487,7 @@ Tilemap:
e32: 0 e32: 0
e33: 1 e33: 1
m_TileColorArray: m_TileColorArray:
- m_RefCount: 88 - m_RefCount: 90
m_Data: {r: 1, g: 1, b: 1, a: 1} m_Data: {r: 1, g: 1, b: 1, a: 1}
m_TileObjectToInstantiateArray: [] m_TileObjectToInstantiateArray: []
m_AnimationFrameRate: 1 m_AnimationFrameRate: 1
@ -1528,6 +1556,82 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3} m_CorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
m_PrefabInstance: {fileID: 91367892} m_PrefabInstance: {fileID: 91367892}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1052407373
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 557650576}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b68250b34a148164d9a00b31f0af63d8, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
moveSpeed: 9
jumpSpeed: 18.2
jumpCutMultiplier: 0.3
attackBoxSize: {x: 3, y: 1}
enemyLayer:
serializedVersion: 2
m_Bits: 64
minJumpDuration: 0.1
dashTime: 0.5
dashDistance: 5
--- !u!1 &1117392520 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3345230653483034275, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
m_PrefabInstance: {fileID: 960162597646736108}
m_PrefabAsset: {fileID: 0}
--- !u!212 &1117392523 stripped
SpriteRenderer:
m_CorrespondingSourceObject: {fileID: 3818235801779510969, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
m_PrefabInstance: {fileID: 960162597646736108}
m_PrefabAsset: {fileID: 0}
--- !u!50 &1117392525
Rigidbody2D:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1117392520}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDamping: 0
m_AngularDamping: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 2
--- !u!114 &1117392526
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1117392520}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e036d2115ad53f48ba9c059c6cea1bb, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::GroundEnemyMovement
data: {fileID: 11400000, guid: a5edb67c4940a4e4692478c7267fc1f8, type: 2}
rigidBody: {fileID: 1117392525}
spriteRenderer: {fileID: 1117392523}
Speed: 3
startDirection: 1.5
--- !u!1001 &960162597646736108 --- !u!1001 &960162597646736108
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1536,13 +1640,17 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 3096000554608240826, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
propertyPath: m_IsTrigger
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3} - target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: -0.43 value: -0.43
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3} - target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: -0.11 value: -0.66
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3} - target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
@ -1580,10 +1688,21 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: TestEntity value: TestEntity
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] - target: {fileID: 4449206212094151330, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 4449206212094151330, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 3345230653483034275, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
insertIndex: -1
addedObject: {fileID: 1117392526}
- targetCorrespondingSourceObject: {fileID: 3345230653483034275, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
insertIndex: -1
addedObject: {fileID: 1117392525}
m_SourcePrefab: {fileID: 100100000, guid: a5f5cf89603320347975ecc8f39129b7, type: 3} m_SourcePrefab: {fileID: 100100000, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
--- !u!1660057539 &9223372036854775807 --- !u!1660057539 &9223372036854775807
SceneRoots: SceneRoots:

View File

@ -3,41 +3,45 @@ using UnityEngine.Events;
public class Entity : MonoBehaviour public class Entity : MonoBehaviour
{ {
private int maxHealth; private int maxHp;
private int currentHealth; private int currentHp;
private int attackDamage; private int attackDamage;
[SerializeField] private EntityData data; [SerializeField] private EntityData data;
void Awake() void Awake()
{ {
maxHealth = data.maxHealth; maxHp = data.maxHealth;
currentHealth = data.maxHealth; currentHp = data.maxHealth;
attackDamage = data.attackDamage; attackDamage = data.attackDamage;
} }
public virtual void TakeDamage(int playerAttackDamage) public virtual void TakeDamage(int playerAttackDamage)
{ {
currentHealth -= playerAttackDamage; currentHp -= playerAttackDamage;
if (currentHealth <= 0) if (currentHp <= 0)
{ {
currentHealth = 0; currentHp = 0;
Destroy(gameObject); Destroy(gameObject);
} }
} }
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
Destroy(gameObject);
}
}
void Update() void Update()
{ {
RunAI(); this.RunAI();
} }
protected void RunAI() { } public virtual void RunAI()
public int getAttackDamage()
{ {
return attackDamage;
} }
}
}

View File

@ -1,4 +1,5 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
@ -6,22 +7,39 @@ using UnityEngine.InputSystem;
public class Player : MonoBehaviour public class Player : MonoBehaviour
{ {
private int currentHealth; private Camera _camera;
private int maxHealth; private Rigidbody2D _rigidbody2D;
private int currentHp;
private int maxHp;
private int maxJumpCount = 2; private int maxJumpCount = 2;
private int currentJumpCount = 2; private int currentJumpCount = 2;
private float moveX;
private bool isGrounded;
private bool isDashing;
private Coroutine jumpCutRoutine;
private List<GameObject> dashHitEnemies = new List<GameObject>();
[SerializeField] private float moveSpeed = 9f; [SerializeField] private float moveSpeed = 9f;
[SerializeField] private float jumpSpeed = 18.2f; [SerializeField] private float jumpSpeed = 18.2f;
[SerializeField] private float jumpCutMultiplier = 0.3f; [SerializeField] private float jumpCutMultiplier = 0.3f;
[SerializeField] private Vector2 attackBoxSize = new Vector2(1f, 1f);
[SerializeField] private LayerMask enemyLayer;
[SerializeField] private float dashTime = 0.5f;
[SerializeField] private float dashDistance = 5f;
private Rigidbody2D _rigidbody; private Rigidbody2D _rigidbody;
private void Start() private void Start()
{ {
_rigidbody = gameObject.GetComponent<Rigidbody2D>(); _rigidbody = gameObject.GetComponent<Rigidbody2D>();
_camera = Camera.main;
} }
public void Jump() public void Jump()
@ -32,19 +50,138 @@ public class Player : MonoBehaviour
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0); _rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0);
_rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse); _rigidbody.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
} }
} }
public void MoveUpdate()
{
if (!isDashing)
{
_rigidbody.linearVelocity = new Vector2(moveX * moveSpeed, _rigidbody.linearVelocity.y);
}
}
public void SetXVector(InputValue value)
{
moveX = value.Get<Vector2>().x;
}
public void NormalAttack()
{
float angle = GetMouseAngle();
Vector2 direction = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));
Vector2 originPosition = (Vector2)transform.position + (direction * 1);
Collider2D[] enemise = Physics2D.OverlapBoxAll(originPosition, attackBoxSize, angle, enemyLayer);
Debug.Log(angle);
if (enemise.Length > 0)
{
foreach (Collider2D enemy in enemise)
{
Debug.Log(enemy.name);
enemy.gameObject.GetComponent<Entity>().TakeDamage(10);
}
if (angle > -110 && angle < -70)
{
_rigidbody.linearVelocity = new Vector2(-_rigidbody.linearVelocity.x, 20f);
}
}
}
private void CutJumpVelocity()
{
if (_rigidbody.linearVelocity.y > 0)
{
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, _rigidbody.linearVelocity.y * jumpCutMultiplier);
}
}
private IEnumerator DelayedJumpCut(float delay)
{
yield return new WaitForSeconds(delay);
CutJumpVelocity();
}
public void CheckGround()
{
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, 1.25f, LayerMask.GetMask("Ground"));
if (isGrounded) { currentJumpCount = maxJumpCount; }
}
private float GetMouseAngle()
{
Vector2 tempVect = _camera.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - transform.position;
return Mathf.Atan2(tempVect.y, tempVect.x) * Mathf.Rad2Deg;
}
public void DashAttack()
{
if (isDashing) return;
StartCoroutine(DashPlayerRoutine());
}
private IEnumerator DashPlayerRoutine()
{
isDashing = true;
_rigidbody.linearVelocity = Vector2.zero;
dashHitEnemies.Clear();
Vector2 mousePos = _camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
Vector2 direction = (mousePos - (Vector2)transform.position).normalized;
if (isGrounded && mousePos.y < transform.position.y)
{
direction = new Vector2(Mathf.Sign(direction.x), 0);
}
Vector2 startPos = _rigidbody.position;
Vector2 targetPos = startPos + (direction * dashDistance);
float dashTimer = 0f;
while (dashTimer < dashTime)
{
dashTimer += Time.deltaTime;
float t = dashTimer / dashTime;
_rigidbody.MovePosition(Vector2.Lerp(startPos, targetPos, t));
yield return null;
}
isDashing = false;
}
public void AttackOnDash(Collider2D collision)
{
if ((enemyLayer.value & (1 << collision.gameObject.layer)) > 0)
{
if (!dashHitEnemies.Contains(collision.gameObject))
{
dashHitEnemies.Add(collision.gameObject);
Debug.Log(collision.gameObject.name + " 대쉬 피격");
collision.gameObject.GetComponent<Entity>().TakeDamage(10);
}
}
}
public bool IsDashing() { return isDashing; }
public void Heal(int heal) public void Heal(int heal)
{ {
if (heal < 0) { return; } if (heal < 0) { return; }
currentHealth += heal; currentHp += heal;
if (currentHealth > maxHealth) if (currentHp > maxHp)
{ {
currentHealth = maxHealth; currentHp = maxHp;
} }
} }
public void TakeDamage(int playerAttackDamage)
{
currentHp -= playerAttackDamage;
if (currentHp <= 0)
{
currentHp = 0;
Destroy(gameObject);
}
}
} }

View File

@ -6,199 +6,54 @@ using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour public class PlayerController : MonoBehaviour
{ {
private Player player; private Player player;
private int currentHealth;
private int maxHealth;
private Rigidbody2D _rigidbody;
private Camera _camera;
private int maxJumpCount = 2;
private int currentJumpCount = 2;
private bool isGrounded;
private bool isDashing;
private Vector2 inputVector; private Vector2 inputVector;
private float jumpStartTime; private float jumpStartTime;
private Coroutine jumpCutRoutine;
private List<GameObject> dashHitEnemies = new List<GameObject>();
[SerializeField] private float moveSpeed = 9f;
[SerializeField] private float jumpSpeed = 18.2f;
[SerializeField] private float jumpCutMultiplier = 0.3f;
[SerializeField] private float minJumpDuration = 0.1f;
[SerializeField] private float dashTime = 0.5f;
[SerializeField] private float dashDistance = 5f;
[SerializeField] private LayerMask enemyLayer;
[SerializeField] private Vector2 attackBoxSize = new Vector2(1f, 1f);
private void Start() private void Start()
{ {
player = GetComponent<Player>(); player = GetComponent<Player>();
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
_camera = Camera.main;
} }
private void FixedUpdate() private void FixedUpdate()
{ {
isGrounded = CheckGround(); player.MoveUpdate();
MovePlayer();
InitJumpCount();
Debug.DrawRay(transform.position, Vector2.down * 1.25f, Color.red); Debug.DrawRay(transform.position, Vector2.down * 1.25f, Color.red);
player.CheckGround();
} }
private void OnMove(InputValue value) private void OnMove(InputValue value)
{ {
Vector2 input = value.Get<Vector2>(); player.SetXVector(value);
inputVector = new Vector2(input.x * moveSpeed, 0);
} }
private void OnAttack(InputValue value) private void OnAttack(InputValue value)
{ {
if (isDashing) return; if (player.IsDashing()) return;
if (value.isPressed) if (value.isPressed)
{ {
if (Mouse.current.leftButton.isPressed) if (Mouse.current.leftButton.isPressed)
{ {
NormalAttack(); player.NormalAttack();
} else if (Mouse.current.rightButton.isPressed) }
else if (Mouse.current.rightButton.isPressed)
{ {
DashAttack(); player.DashAttack();
} }
} }
} }
private void OnJump(InputValue value) private void OnJump(InputValue value)
{ {
player.Jump(); if(value.isPressed) { player.Jump(); }
} }
private void NormalAttack() private void OnTriggerEnter2D(Collider2D collision)
{ {
float angle = GetMouseAngle(); if (player.IsDashing())
Vector2 direction = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));
Vector2 originPosition = (Vector2)transform.position + (direction * 1);
Collider2D[] enemise = Physics2D.OverlapBoxAll(originPosition, attackBoxSize, angle, enemyLayer);
Debug.Log(angle);
if (enemise.Length > 0)
{ {
foreach (Collider2D enemy in enemise) player.AttackOnDash(collision);
{
Debug.Log(enemy.name);
enemy.gameObject.GetComponent<Entity>().TakeDamage(10);
}
if (angle > -110 && angle < -70)
{
DownAttackLeap();
}
}
}
private void DownAttackLeap()
{
_rigidbody.linearVelocity = new Vector2(-_rigidbody.linearVelocity.x, 20f);
}
private void DashAttack()
{
if (isDashing) return;
StartCoroutine(DashPlayerRoutine());
}
private IEnumerator DashPlayerRoutine()
{
isDashing = true;
_rigidbody.linearVelocity = Vector2.zero;
dashHitEnemies.Clear();
Vector2 mousePos = _camera.ScreenToWorldPoint(Mouse.current.position.ReadValue());
Vector2 direction = (mousePos - (Vector2)transform.position).normalized;
if (isGrounded && mousePos.y < transform.position.y)
{
direction = new Vector2(Mathf.Sign(direction.x), 0);
}
Vector2 startPos = _rigidbody.position;
Vector2 targetPos = startPos + (direction * dashDistance);
float dashTimer = 0f;
while (dashTimer < dashTime)
{
dashTimer += Time.deltaTime;
float t = dashTimer / dashTime;
_rigidbody.MovePosition(Vector2.Lerp(startPos, targetPos, t));
yield return null;
}
isDashing = false;
}
private void MovePlayer()
{
if(!isDashing)
_rigidbody.linearVelocity = new Vector2(inputVector.x, _rigidbody.linearVelocity.y);
}
private float GetMouseAngle()
{
Vector2 tempVect = _camera.ScreenToWorldPoint(Mouse.current.position.ReadValue()) - transform.position;
return Mathf.Atan2(tempVect.y, tempVect.x) * Mathf.Rad2Deg;
}
private void CutJumpVelocity()
{
if (_rigidbody.linearVelocity.y > 0)
{
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, _rigidbody.linearVelocity.y * jumpCutMultiplier);
} }
} }
private IEnumerator DelayedJumpCut(float delay)
{
yield return new WaitForSeconds(delay);
CutJumpVelocity();
}
private bool CheckGround()
{
return Physics2D.Raycast(transform.position, Vector2.down, 1.25f, LayerMask.GetMask("Ground"));
}
private void InitJumpCount()
{
if (isGrounded && _rigidbody.linearVelocity.y <= 0.1f)
{
currentJumpCount = maxJumpCount;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (isDashing)
{
if ((enemyLayer.value & (1 << collision.gameObject.layer)) > 0)
{
if (!dashHitEnemies.Contains(collision.gameObject))
{
dashHitEnemies.Add(collision.gameObject);
Debug.Log(collision.gameObject.name + " 대쉬 피격");
collision.gameObject.GetComponent<Entity>().TakeDamage(10);
}
}
}
}
} }

View File

@ -5,10 +5,10 @@ public class FlyEnemyMovement : Entity
{ {
private GameObject playerObject; private GameObject playerObject;
private NavMeshAgent agent; private NavMeshAgent agent;
[SerializeField]
private float detectionRange = 5.0f; // 감지 범위 변수 [SerializeField] private float detectionRange = 5.0f; // 감지 범위 변수
[SerializeField] [SerializeField] private float EnemyTime;
private float EnemyTime;
private void Awake() private void Awake()
{ {
agent = GetComponent<NavMeshAgent>(); agent = GetComponent<NavMeshAgent>();
@ -23,18 +23,18 @@ public class FlyEnemyMovement : Entity
playerObject = GameObject.FindWithTag("Player"); playerObject = GameObject.FindWithTag("Player");
} }
void Update() public override void RunAI()
{ {
if (playerObject != null) if (playerObject != null)
{ {
// 1. 현재 위치와 플레이어 위치 사이의 거리를 계산 // 1. 현재 위치와 플레이어 위치 사이의 거리를 계산
float distance = Vector3.Distance(transform.position, playerObject.transform.position); float distance = Vector3.Distance(transform.position, playerObject.transform.position);
// 2. 거리가 감지 범위 확인
if (distance <= detectionRange) if (distance <= detectionRange)
{ {
SetAgentPosition(); // 추격 시작 SetAgentPosition(); // 추격 시작
}else }
else
{ {
// 범위 밖이라면 이동을 멈춤 // 범위 밖이라면 이동을 멈춤
if (!agent.isStopped) if (!agent.isStopped)
@ -56,13 +56,6 @@ public class FlyEnemyMovement : Entity
agent.SetDestination(new Vector3(targetPos.x, targetPos.y)); agent.SetDestination(new Vector3(targetPos.x, targetPos.y));
} }
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
Die();
}
}
private void OnDrawGizmosSelected() private void OnDrawGizmosSelected()
{ {
Gizmos.color = Color.red; Gizmos.color = Color.red;

View File

@ -3,14 +3,10 @@ using System.Collections.Generic;
public class GroundEnemyMovement : Entity public class GroundEnemyMovement : Entity
{ {
[SerializeField] [SerializeField] private Rigidbody2D rigidBody;
private Rigidbody2D rigidBody; [SerializeField] private SpriteRenderer spriteRenderer;
[SerializeField] [SerializeField] private float Speed = 3f;
private SpriteRenderer spriteRenderer; [SerializeField] private float startDirection = 1.5f;
[SerializeField]
private float Speed = 3f;
[SerializeField]
private float startDirection = 1.5f;
private float currentDirection; private float currentDirection;
private float halfWidth; private float halfWidth;
@ -23,7 +19,7 @@ public class GroundEnemyMovement : Entity
spriteRenderer.flipX = currentDirection == 1 ? false : true; spriteRenderer.flipX = currentDirection == 1 ? false : true;
} }
void FixedUpdate() public override void RunAI()
{ {
movemenet.x = Speed * currentDirection; movemenet.x = Speed * currentDirection;
movemenet.y = rigidBody.linearVelocity.y; movemenet.y = rigidBody.linearVelocity.y;
@ -41,7 +37,8 @@ public class GroundEnemyMovement : Entity
{ {
frontVec += Vector2.right * halfWidth; frontVec += Vector2.right * halfWidth;
wallDir = Vector2.right; wallDir = Vector2.right;
}else }
else
{ {
frontVec += Vector2.left * halfWidth; frontVec += Vector2.left * halfWidth;
wallDir = Vector2.left; wallDir = Vector2.left;
@ -56,22 +53,8 @@ public class GroundEnemyMovement : Entity
if (cliffHit.collider == null || wallHit.collider != null) if (cliffHit.collider == null || wallHit.collider != null)
{ {
Turn(); currentDirection *= -1;
} spriteRenderer.flipX = !spriteRenderer.flipX;
}
private void Turn()
{
currentDirection *= -1;
spriteRenderer.flipX = !spriteRenderer.flipX;
}
private void OnCollisionEnter2D(Collision2D collision)
{
// 부딪힌 물체의 태그가 "Player"라면
if (collision.gameObject.CompareTag("Player"))
{
Die();
} }
} }
} }

View File

@ -8,6 +8,7 @@
"com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap": "1.0.0",
"com.unity.2d.tilemap.extras": "6.0.1", "com.unity.2d.tilemap.extras": "6.0.1",
"com.unity.2d.tooling": "1.0.0", "com.unity.2d.tooling": "1.0.0",
"com.unity.ai.navigation": "2.0.9",
"com.unity.collab-proxy": "2.11.2", "com.unity.collab-proxy": "2.11.2",
"com.unity.ide.rider": "3.0.38", "com.unity.ide.rider": "3.0.38",
"com.unity.ide.visualstudio": "2.0.26", "com.unity.ide.visualstudio": "2.0.26",

View File

@ -99,6 +99,15 @@
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.ai.navigation": {
"version": "2.0.9",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.ai": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.burst": { "com.unity.burst": {
"version": "1.8.27", "version": "1.8.27",
"depth": 2, "depth": 2,

View File

@ -295,7 +295,99 @@ PlayerSettings:
AndroidReportGooglePlayAppDependencies: 1 AndroidReportGooglePlayAppDependencies: 1
androidSymbolsSizeThreshold: 800 androidSymbolsSizeThreshold: 800
m_BuildTargetIcons: [] m_BuildTargetIcons: []
m_BuildTargetPlatformIcons: [] m_BuildTargetPlatformIcons:
- m_BuildTarget: Android
m_Icons:
- m_Textures: []
m_Width: 432
m_Height: 432
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 324
m_Height: 324
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 216
m_Height: 216
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 162
m_Height: 162
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 108
m_Height: 108
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 81
m_Height: 81
m_Kind: 2
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 1
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 0
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 0
m_SubKind:
m_BuildTargetBatching: [] m_BuildTargetBatching: []
m_BuildTargetShaderSettings: [] m_BuildTargetShaderSettings: []
m_BuildTargetGraphicsJobs: [] m_BuildTargetGraphicsJobs: []