From 393b538920eaf3c843faad2f84637646ca0217f5 Mon Sep 17 00:00:00 2001 From: Fiore Date: Tue, 29 Apr 2025 11:43:58 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20bullet=20base=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 이동속도, 데미지, 라이프타임을 받음 - bulletdata를 받아 초기화 진행 - 발사 위치를 기준으로 목표 방향 세팅 - 테스트를 위해 초기값 임의로 작성 work in DEG-100 JIRA --- .../Character/Enemy/Bullet/BulletBase.cs | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Character/Enemy/Bullet/BulletBase.cs b/Assets/Scripts/Character/Enemy/Bullet/BulletBase.cs index 7631b85e..2396961b 100644 --- a/Assets/Scripts/Character/Enemy/Bullet/BulletBase.cs +++ b/Assets/Scripts/Character/Enemy/Bullet/BulletBase.cs @@ -14,12 +14,60 @@ public struct BulletData LifeTime = lifeTime; Speed = speed; } - } - +[RequireComponent(typeof(Collider))] public class BulletBase : MonoBehaviour { - private float _speed; - private Vector3 _targetPosition; + // 데이터 + private float _speed = 5f; + private float _damage = 1f; + private float _lifeTime = 10f; + // 내부용 + private Vector3 _direction = Vector3.forward; + private float _timer; + + public virtual void Initialize(BulletData bulletData) + { + _speed = bulletData.Speed; + _damage = bulletData.Damage; + _lifeTime = bulletData.LifeTime; + + // 발사 위치 기준 목표 방향만 계산 + _direction = (bulletData.TargetPos - transform.position).normalized; + + // 탄환이 바라보는 방향 세팅 + transform.rotation = Quaternion.LookRotation(_direction); + + _timer = 0f; + } + + private void Update() + { + // 1) 이동 + transform.position += _direction * (_speed * Time.deltaTime); + + // 2) 수명 카운트 + _timer += Time.deltaTime; + if (_timer >= _lifeTime) + { + DestroyBullet(); + } + } + + private void OnTriggerEnter(Collider other) + { + var character = other.GetComponent(); + if (character != null) + { + character.TakeDamage(_damage); + DestroyBullet(); + } + } + + protected virtual void DestroyBullet() + { + Debug.Log("## Bullet destroyed"); + Destroy(gameObject); + } } \ No newline at end of file