CapersProject/Assets/02.Scripts/Prop/Rockfall.cs
Nam Tae Gun 4db6c2bf57 #17 모래두더지 구르기 스킬(SingleRoll) 추가
+ BaseSkillData에서 TargetLayer를 받아오게끔 로직 수정(스킬마다의 Target이 다름)
+ DamageableProps 태그 추가
+ DamageableProps 부모 클래스 추가
+ DamageableProps 상속 클래스 Rockfall 추가
+ SandMole(모래두더지)가 벽에 박치기 한 뒤에 Rockfall(낙석)을 떨어뜨리는 기능 추가
2024-06-14 18:11:35 +09:00

81 lines
2.5 KiB
C#

using System.Collections;
using BlueWater.Audios;
using BlueWater.Interfaces;
using BlueWater.Maps;
using Sirenix.OdinInspector;
using UnityEngine;
namespace BlueWater
{
public class Rockfall : DamageableProps
{
[Title("컴포넌트")]
[SerializeField]
private Rigidbody _rigidbody;
[SerializeField, Required]
private SphereCollider _sphereCollider;
[Title("충돌 설정")]
[SerializeField]
private LayerMask _targetLayer;
[SerializeField]
private LayerMask _groundLayer;
[SerializeField, Range(0f, 1f)]
private float _checkDistance = 0.1f;
[SerializeField, Range(0, 5)]
private int _attackDamage = 1;
[Title("Ground Crash 설정")]
[SerializeField]
private string _groundCrashSfxName;
[SerializeField]
private ParticleSystem _groundCrashParticle;
private Collider[] _hitColliders = new Collider[4];
private bool _isGrounded;
private bool _isAttacked;
private IEnumerator Start()
{
_sphereCollider.enabled = false;
SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation;
while (!_isGrounded)
{
_isGrounded = Physics.Raycast(transform.position, Vector3.down, _checkDistance, _groundLayer);
yield return null;
}
if (_rigidbody)
{
_rigidbody.isKinematic = true;
}
_sphereCollider.enabled = true;
if (!string.IsNullOrEmpty(_groundCrashSfxName))
{
AudioManager.Instance.PlaySfx(_groundCrashSfxName);
}
if (_groundCrashParticle && SpawnLocation)
{
Instantiate(_groundCrashParticle, transform.position, Quaternion.identity, SpawnLocation);
}
var hitCount = Physics.OverlapSphereNonAlloc(_sphereCollider.bounds.center, _sphereCollider.radius,
_hitColliders, _targetLayer, QueryTriggerInteraction.Collide);
for (var i = 0; i < hitCount; i++)
{
var hitCollider = _hitColliders[i];
var iDamageable = hitCollider.GetComponentInParent<IDamageable>();
if (iDamageable == null || !iDamageable.CanDamage()) continue;
iDamageable.TakeDamage(_attackDamage);
}
}
}
}