코드 리펙토링
This commit is contained in:
parent
79d947d176
commit
8e46b58e61
|
|
@ -72,7 +72,7 @@
|
|||
"name": "",
|
||||
"id": "27687542-09ec-47b5-8f6c-5c672da72b21",
|
||||
"path": "<Keyboard>/space",
|
||||
"interactions": "Press(pressPoint=1.401298E-45,behavior=2)",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Jump",
|
||||
|
|
|
|||
|
|
@ -105,7 +105,6 @@ GameObject:
|
|||
- component: {fileID: 2556996269222904179}
|
||||
- component: {fileID: 6376878406717916855}
|
||||
- component: {fileID: 4035999004062947863}
|
||||
- component: {fileID: 1888074432508430436}
|
||||
m_Layer: 0
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
|
|
@ -294,32 +293,3 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: eae62c41ce858ce478f29843ba0d3dea, type: 3}
|
||||
m_Name:
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -181,7 +181,10 @@ PrefabInstance:
|
|||
- targetCorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
|
||||
insertIndex: -1
|
||||
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}
|
||||
--- !u!1 &435424068
|
||||
GameObject:
|
||||
|
|
@ -365,6 +368,11 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1052407366}
|
||||
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
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -1248,6 +1256,26 @@ Tilemap:
|
|||
m_TileObjectToInstantiateIndex: 65535
|
||||
dummyAlignment: 0
|
||||
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}
|
||||
second:
|
||||
serializedVersion: 2
|
||||
|
|
@ -1430,17 +1458,17 @@ Tilemap:
|
|||
m_AllTileFlags: 1073741825
|
||||
m_AnimatedTiles: {}
|
||||
m_TileAssetArray:
|
||||
- m_RefCount: 88
|
||||
- m_RefCount: 90
|
||||
m_Data: {fileID: 11400000, guid: 8309c65724c3a8e40884dda0cfb55bae, type: 2}
|
||||
- m_RefCount: 0
|
||||
m_Data: {fileID: 0}
|
||||
m_TileSpriteArray:
|
||||
- m_RefCount: 88
|
||||
- m_RefCount: 90
|
||||
m_Data: {fileID: -855298285791758126, guid: 9fc32b26c4b0b87459965e872a8507d2, type: 3}
|
||||
- m_RefCount: 0
|
||||
m_Data: {fileID: 0}
|
||||
m_TileMatrixArray:
|
||||
- m_RefCount: 88
|
||||
- m_RefCount: 90
|
||||
m_Data:
|
||||
e00: 1
|
||||
e01: 0
|
||||
|
|
@ -1459,7 +1487,7 @@ Tilemap:
|
|||
e32: 0
|
||||
e33: 1
|
||||
m_TileColorArray:
|
||||
- m_RefCount: 88
|
||||
- m_RefCount: 90
|
||||
m_Data: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_TileObjectToInstantiateArray: []
|
||||
m_AnimationFrameRate: 1
|
||||
|
|
@ -1528,6 +1556,82 @@ Transform:
|
|||
m_CorrespondingSourceObject: {fileID: 4539706167822133972, guid: ae58a5fa402b1d941b0878d356d1389d, type: 3}
|
||||
m_PrefabInstance: {fileID: 91367892}
|
||||
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
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -1536,13 +1640,17 @@ PrefabInstance:
|
|||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 3096000554608240826, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
|
||||
propertyPath: m_IsTrigger
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -0.43
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: -0.11
|
||||
value: -0.66
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3182903703610233758, guid: a5f5cf89603320347975ecc8f39129b7, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
|
|
@ -1580,10 +1688,21 @@ PrefabInstance:
|
|||
propertyPath: m_Name
|
||||
value: TestEntity
|
||||
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_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}
|
||||
--- !u!1660057539 &9223372036854775807
|
||||
SceneRoots:
|
||||
|
|
|
|||
|
|
@ -3,41 +3,45 @@ using UnityEngine.Events;
|
|||
|
||||
public class Entity : MonoBehaviour
|
||||
{
|
||||
private int maxHealth;
|
||||
private int currentHealth;
|
||||
private int maxHp;
|
||||
private int currentHp;
|
||||
private int attackDamage;
|
||||
|
||||
[SerializeField] private EntityData data;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
maxHealth = data.maxHealth;
|
||||
currentHealth = data.maxHealth;
|
||||
maxHp = data.maxHealth;
|
||||
currentHp = data.maxHealth;
|
||||
attackDamage = data.attackDamage;
|
||||
}
|
||||
|
||||
public virtual void TakeDamage(int playerAttackDamage)
|
||||
{
|
||||
currentHealth -= playerAttackDamage;
|
||||
if (currentHealth <= 0)
|
||||
currentHp -= playerAttackDamage;
|
||||
if (currentHp <= 0)
|
||||
{
|
||||
currentHealth = 0;
|
||||
currentHp = 0;
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
other.gameObject.GetComponent<Player>().TakeDamage(attackDamage);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
RunAI();
|
||||
this.RunAI();
|
||||
}
|
||||
|
||||
protected void RunAI() { }
|
||||
|
||||
|
||||
public int getAttackDamage()
|
||||
public virtual void RunAI()
|
||||
{
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
|
@ -6,22 +7,39 @@ using UnityEngine.InputSystem;
|
|||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
private int currentHealth;
|
||||
private int maxHealth;
|
||||
private Camera _camera;
|
||||
private Rigidbody2D _rigidbody2D;
|
||||
|
||||
private int currentHp;
|
||||
private int maxHp;
|
||||
|
||||
private int maxJumpCount = 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 jumpSpeed = 18.2f;
|
||||
[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 void Start()
|
||||
{
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
public void Jump()
|
||||
|
|
@ -32,19 +50,138 @@ public class Player : MonoBehaviour
|
|||
_rigidbody.linearVelocity = new Vector2(_rigidbody.linearVelocity.x, 0);
|
||||
_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)
|
||||
{
|
||||
if (heal < 0) { return; }
|
||||
|
||||
currentHealth += heal;
|
||||
if (currentHealth > maxHealth)
|
||||
currentHp += heal;
|
||||
if (currentHp > maxHp)
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
currentHp = maxHp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void TakeDamage(int playerAttackDamage)
|
||||
{
|
||||
currentHp -= playerAttackDamage;
|
||||
if (currentHp <= 0)
|
||||
{
|
||||
currentHp = 0;
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,199 +6,54 @@ using UnityEngine.InputSystem;
|
|||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
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 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()
|
||||
{
|
||||
player = GetComponent<Player>();
|
||||
_rigidbody = gameObject.GetComponent<Rigidbody2D>();
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
isGrounded = CheckGround();
|
||||
MovePlayer();
|
||||
InitJumpCount();
|
||||
|
||||
player.MoveUpdate();
|
||||
Debug.DrawRay(transform.position, Vector2.down * 1.25f, Color.red);
|
||||
player.CheckGround();
|
||||
}
|
||||
|
||||
private void OnMove(InputValue value)
|
||||
{
|
||||
Vector2 input = value.Get<Vector2>();
|
||||
inputVector = new Vector2(input.x * moveSpeed, 0);
|
||||
player.SetXVector(value);
|
||||
}
|
||||
|
||||
private void OnAttack(InputValue value)
|
||||
{
|
||||
if (isDashing) return;
|
||||
if (player.IsDashing()) return;
|
||||
if (value.isPressed)
|
||||
{
|
||||
if (Mouse.current.leftButton.isPressed)
|
||||
{
|
||||
NormalAttack();
|
||||
} else if (Mouse.current.rightButton.isPressed)
|
||||
player.NormalAttack();
|
||||
}
|
||||
else if (Mouse.current.rightButton.isPressed)
|
||||
{
|
||||
DashAttack();
|
||||
player.DashAttack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnJump(InputValue value)
|
||||
{
|
||||
player.Jump();
|
||||
}
|
||||
|
||||
private 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if(value.isPressed) { player.Jump(); }
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (isDashing)
|
||||
if (player.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);
|
||||
player.AttackOnDash(collision);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,10 +5,10 @@ public class FlyEnemyMovement : Entity
|
|||
{
|
||||
private GameObject playerObject;
|
||||
private NavMeshAgent agent;
|
||||
[SerializeField]
|
||||
private float detectionRange = 5.0f; // 감지 범위 변수
|
||||
[SerializeField]
|
||||
private float EnemyTime;
|
||||
|
||||
[SerializeField] private float detectionRange = 5.0f; // 감지 범위 변수
|
||||
[SerializeField] private float EnemyTime;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
|
|
@ -23,18 +23,18 @@ public class FlyEnemyMovement : Entity
|
|||
playerObject = GameObject.FindWithTag("Player");
|
||||
}
|
||||
|
||||
void Update()
|
||||
public override void RunAI()
|
||||
{
|
||||
if (playerObject != null)
|
||||
{
|
||||
// 1. 현재 위치와 플레이어 위치 사이의 거리를 계산
|
||||
float distance = Vector3.Distance(transform.position, playerObject.transform.position);
|
||||
|
||||
// 2. 거리가 감지 범위 확인
|
||||
if (distance <= detectionRange)
|
||||
{
|
||||
SetAgentPosition(); // 추격 시작
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
// 범위 밖이라면 이동을 멈춤
|
||||
if (!agent.isStopped)
|
||||
|
|
@ -56,13 +56,6 @@ public class FlyEnemyMovement : Entity
|
|||
agent.SetDestination(new Vector3(targetPos.x, targetPos.y));
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
|
|
|
|||
|
|
@ -3,14 +3,10 @@ using System.Collections.Generic;
|
|||
|
||||
public class GroundEnemyMovement : Entity
|
||||
{
|
||||
[SerializeField]
|
||||
private Rigidbody2D rigidBody;
|
||||
[SerializeField]
|
||||
private SpriteRenderer spriteRenderer;
|
||||
[SerializeField]
|
||||
private float Speed = 3f;
|
||||
[SerializeField]
|
||||
private float startDirection = 1.5f;
|
||||
[SerializeField] private Rigidbody2D rigidBody;
|
||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
||||
[SerializeField] private float Speed = 3f;
|
||||
[SerializeField] private float startDirection = 1.5f;
|
||||
|
||||
private float currentDirection;
|
||||
private float halfWidth;
|
||||
|
|
@ -23,7 +19,7 @@ public class GroundEnemyMovement : Entity
|
|||
spriteRenderer.flipX = currentDirection == 1 ? false : true;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
public override void RunAI()
|
||||
{
|
||||
movemenet.x = Speed * currentDirection;
|
||||
movemenet.y = rigidBody.linearVelocity.y;
|
||||
|
|
@ -41,7 +37,8 @@ public class GroundEnemyMovement : Entity
|
|||
{
|
||||
frontVec += Vector2.right * halfWidth;
|
||||
wallDir = Vector2.right;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
frontVec += Vector2.left * halfWidth;
|
||||
wallDir = Vector2.left;
|
||||
|
|
@ -55,23 +52,9 @@ public class GroundEnemyMovement : Entity
|
|||
Debug.DrawRay(transform.position, wallDir * wallDist, Color.blue);
|
||||
|
||||
if (cliffHit.collider == null || wallHit.collider != null)
|
||||
{
|
||||
Turn();
|
||||
}
|
||||
}
|
||||
|
||||
private void Turn()
|
||||
{
|
||||
currentDirection *= -1;
|
||||
spriteRenderer.flipX = !spriteRenderer.flipX;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
// 부딪힌 물체의 태그가 "Player"라면
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
Die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.2d.tilemap.extras": "6.0.1",
|
||||
"com.unity.2d.tooling": "1.0.0",
|
||||
"com.unity.ai.navigation": "2.0.9",
|
||||
"com.unity.collab-proxy": "2.11.2",
|
||||
"com.unity.ide.rider": "3.0.38",
|
||||
"com.unity.ide.visualstudio": "2.0.26",
|
||||
|
|
|
|||
|
|
@ -99,6 +99,15 @@
|
|||
},
|
||||
"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": {
|
||||
"version": "1.8.27",
|
||||
"depth": 2,
|
||||
|
|
|
|||
|
|
@ -295,7 +295,99 @@ PlayerSettings:
|
|||
AndroidReportGooglePlayAppDependencies: 1
|
||||
androidSymbolsSizeThreshold: 800
|
||||
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_BuildTargetShaderSettings: []
|
||||
m_BuildTargetGraphicsJobs: []
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user