캐릭터 기본 공격 영역 로직 적용
This commit is contained in:
@@ -7,7 +7,6 @@ namespace TON
|
||||
public class CharacterBase : MonoBehaviour, IDamage
|
||||
{
|
||||
|
||||
|
||||
public float currentHP;
|
||||
public float maxHP;
|
||||
public float currentSP;
|
||||
@@ -20,6 +19,7 @@ namespace TON
|
||||
|
||||
|
||||
public Transform firePoint; // 스킬 발사 위치
|
||||
public CollisionDetector attackCollider; // 기본 공격 감지를 위한 자식 오브젝트
|
||||
|
||||
public Animator animator;
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace TON
|
||||
joystick = ControllerUI.Instance.joystick;
|
||||
ControllerUI.Instance.linkedCharactor = this;
|
||||
|
||||
attackCollider.EnableCollider(false); // 기본 공격 Enable 비활성화
|
||||
|
||||
Initialize();
|
||||
}
|
||||
|
||||
@@ -45,6 +47,11 @@ namespace TON
|
||||
currentSP = maxSP = playerData.mp;
|
||||
}
|
||||
|
||||
public void UpdateExpericenPoint(float point)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
|
||||
@@ -113,25 +120,35 @@ namespace TON
|
||||
{
|
||||
// 공격 애니메이션 적용
|
||||
animator.Play("Default Attack");
|
||||
|
||||
// 공격 범위 Collider 활성화
|
||||
attackCollider.EnableCollider(true);
|
||||
|
||||
// 일정 시간 후 Collider 다시 비활성화 (예: 0.5초 후)
|
||||
Invoke("DisableAttackCollider", 0.5f);
|
||||
}
|
||||
|
||||
private void DisableAttackCollider()
|
||||
{
|
||||
attackCollider.EnableCollider(false);
|
||||
}
|
||||
|
||||
public void SkillAttack(string skillName)
|
||||
{
|
||||
animator.Play("Skill Attack");
|
||||
|
||||
// 총알 생성
|
||||
// 스킬 생성
|
||||
GameObject skill = ObjectPoolManager.Instance.GetEffect(skillName);
|
||||
|
||||
// skill.transform.SetParent(firePoint);
|
||||
skill.transform.SetPositionAndRotation(firePoint.position, firePoint.rotation);
|
||||
|
||||
|
||||
// 🔥 총알 방향 반전
|
||||
// 🔥 스킬 방향 반전
|
||||
var bulletScale = skill.transform.localScale;
|
||||
bulletScale.x = Mathf.Abs(bulletScale.x) * lastDirection;
|
||||
skill.transform.localScale = bulletScale;
|
||||
|
||||
// 총알 이동 방향 설정
|
||||
// 스킬 이동 방향 설정
|
||||
Rigidbody2D skillRb = skill.GetComponent<Rigidbody2D>();
|
||||
skillRb.velocity = new Vector2(lastDirection * 5f, 0f);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class CollisionDetector : MonoBehaviour
|
||||
{
|
||||
private Collider2D col; // 자식 오브젝트의 Collider
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
col = GetComponent<Collider2D>();
|
||||
col.enabled = false; // 초기에는 감지 비활성화
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (!col.enabled) return; // Collider가 활성화된 경우에만 실행
|
||||
|
||||
if (collision.CompareTag("Monster")) // 적과 충돌 시 제거
|
||||
{
|
||||
collision.GetComponent<IDamage>().ApplyDamage(10f);
|
||||
}
|
||||
}
|
||||
|
||||
// 부모(캐릭터)에서 호출할 메서드
|
||||
public void EnableCollider(bool isEnabled)
|
||||
{
|
||||
col.enabled = isEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c70bfc4e889c3aa40a51378afd6deda8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user