캐릭터 스킬 공격 투사체 적용

This commit is contained in:
aube.lee
2025-02-03 16:38:11 +09:00
parent 059a5f5be9
commit f0b6359d61
12 changed files with 234 additions and 0 deletions

View File

@@ -16,6 +16,10 @@ namespace TON
public float speed;
public float jumpForce = 5f; // 점프 힘
private bool isGrounded = true; // 플레이어가 바닥에 있는지 여부를 판단
private float lastDirection = 1f; // 기본적으로 오른쪽(1) 바라보는 상태
public Transform firePoint; // 스킬 발사 위치
public Animator animator;
@@ -70,6 +74,12 @@ namespace TON
// 캐릭터가 양방향으로 이동시에 알맞은 방향을 바라보도록 적용
private void Turn(float direction)
{
if (direction != 0)
{
lastDirection = Mathf.Sign(direction); // 마지막 이동 방향 저장
}
var scale = transform.localScale;
scale.x = Mathf.Sign(direction) * Mathf.Abs(scale.x);
@@ -105,6 +115,27 @@ namespace TON
animator.Play("Default Attack");
}
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);
}
public void ApplyDamage(float damage)
{

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dab915d74078caf41bf985d45e8dbb81
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class DarknessBall : PoolAble
{
private float elapsedTime; // 경과 시간 저장 변수
void OnEnable()
{
elapsedTime = 0f; // 오브젝트가 활성화될 때 초기화
}
void Update()
{
elapsedTime += Time.deltaTime; // 경과 시간 누적
// 2초가 지나면 오브젝트 풀에 반환
if (elapsedTime >= 2f)
{
ReleaseObject();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Monster")) // 적과 충돌 시 제거
{
ReleaseObject();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46951a2e33fdd5a409f1579de9b7acfa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class FireBall : PoolAble
{
private float elapsedTime; // 경과 시간 저장 변수
void OnEnable()
{
elapsedTime = 0f; // 오브젝트가 활성화될 때 초기화
}
void Update()
{
elapsedTime += Time.deltaTime; // 경과 시간 누적
// 2초가 지나면 오브젝트 풀에 반환
if (elapsedTime >= 2f)
{
ReleaseObject();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Monster")) // 적과 충돌 시 제거
{
ReleaseObject();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26dd04ed34a3c4042bfbe12766af2d60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class IceBall : PoolAble
{
private float elapsedTime; // 경과 시간 저장 변수
void OnEnable()
{
elapsedTime = 0f; // 오브젝트가 활성화될 때 초기화
}
void Update()
{
elapsedTime += Time.deltaTime; // 경과 시간 누적
// 2초가 지나면 오브젝트 풀에 반환
if (elapsedTime >= 2f)
{
ReleaseObject();
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Monster")) // 적과 충돌 시 제거
{
ReleaseObject();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aa5541b68c81e2347960b5eeaf373bf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -23,5 +23,10 @@ namespace TON
{
linkedCharactor.Attack();
}
public void OnClickSkillButton(string skill)
{
linkedCharactor.SkillAttack(skill);
}
}
}