Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feture: 캐릭터 남모로 바꿈, 패링 클래스 따로 만들어서 구현, 패링,어택 히트박스 가시화 #83

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions Project_Blind/Assets/Resources/Prefabs/fa37f09a250f95a1.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Project_Blind/Assets/Resources/Prefabs/남모.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions Project_Blind/Assets/Resources/Prefabs/남모.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using Unity.VisualScripting.YamlDotNet.Core.Tokens;
using UnityEngine;

namespace Blind
{
public class MeleeAttackable: MonoBehaviour
{
private int x;
private int y;
private int _damage = 0;
private bool canDamage;
private Vector2 size;
Expand All @@ -17,6 +18,8 @@ public class MeleeAttackable: MonoBehaviour
private bool _isSpriteFlip;
public void Init(int x = 1, int y = 1, int _damage = 1)
{
this.x = x;
this.y = y;
this._damage = _damage;
size = new Vector2(x, y);
_attackcontactfilter.layerMask = hitLayer;
Expand All @@ -37,6 +40,15 @@ public void DisableDamage()
{
canDamage = false;
}

public void OnDrawGizmos()
{
Gizmos.color = Color.blue;
if (sprite.flipX) Gizmos.DrawWireCube(new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y , gameObject.transform.position.z), new Vector3(x,y,0));
else Gizmos.DrawWireCube(new Vector3(gameObject.transform.position.x -1, gameObject.transform.position.y , gameObject.transform.position.z), new Vector3(x,y,0));

}

private void FixedUpdate()
{
if (!canDamage) return;
Expand Down
80 changes: 80 additions & 0 deletions Project_Blind/Assets/Scripts/Core/MonoBehaviour/Paringable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using UnityEngine;

namespace Blind
{
public class Paringable: MonoBehaviour
{
private int x;
private int y;
private Vector2 size;
private SpriteRenderer _sprite;
private Collider2D[] _result = new Collider2D[10];
private ContactFilter2D _filter;
private Collider2D _hitObj;
private bool _isFlip;
private bool _isParing;
[SerializeField] private LayerMask _hitLayer;

public void Init(int x = 1, int y = 1)
{
this.x = x;
this.y = y;
size = new Vector2(x, y);
_sprite = GetComponent<SpriteRenderer>();
_filter.layerMask = _hitLayer;
_filter.useLayerMask = true;
if (_sprite != null)
{
_isFlip = _sprite.flipX;
}
}

public void EnParing()
{
_isParing = true;
}

public void DisableParing()
{
_isParing = false;
}

public void OnDrawGizmos()
{
Gizmos.color = Color.red;
if (_sprite.flipX) Gizmos.DrawWireCube(new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y , gameObject.transform.position.z), new Vector3(x,y,0));
else Gizmos.DrawWireCube(new Vector3(gameObject.transform.position.x -1, gameObject.transform.position.y , gameObject.transform.position.z), new Vector3(x,y,0));

}

public void FixedUpdate()
{
if (!_isParing) return;

int facing = 1;
if (_sprite.flipX != _isFlip) facing = -1;
Vector2 pointA = new Vector2(transform.position.x + facing, transform.position.y);
int hitCount = Physics2D.OverlapArea(pointA, size, _filter, _result);
for (int i = 0; i < hitCount; i++)
{
_hitObj = _result[i];
if (_hitObj.tag.Equals("Enemy"))
{
if (_hitObj.GetComponent<EnemyCharacter>() == null)
{
// 패링했을때 적 오브젝트(화살같은)인 경우
}
else
{
if (_hitObj.GetComponent<EnemyCharacter>().isAttack)
{
gameObject.GetComponent<PlayerCharacter>().PlayerInvincibility();
Debug.Log("패링 성공!");
}
}
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading