#17 Rockfall 무한 루프 버그 수정

+ Rockfall 코루틴 방식 -> Update 방식으로 변경 (간헐적으로 무한 루프에 걸리는 버그 테스트 더 필요)
This commit is contained in:
Nam Tae Gun 2024-06-15 11:26:48 +09:00
parent e57dae33c0
commit 65282463e5

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using BlueWater.Audios;
using BlueWater.Interfaces;
@ -45,66 +46,86 @@ namespace BlueWater
private ParticleSystem _groundCrashParticle;
private Collider[] _hitColliders = new Collider[4];
private RaycastHit _raycastHit;
private float _startDistance = float.PositiveInfinity;
private bool _isGrounded;
private bool _isAttacked;
// Hashes
private static readonly int _fillHash = Shader.PropertyToID("_Fill");
private IEnumerator Start()
private void OnDrawGizmos()
{
Debug.DrawRay(transform.position, Vector3.down * _checkDistance, _isGrounded ? Color.blue : Color.red);
}
private void Start()
{
_sphereCollider.enabled = false;
SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation;
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
{
Debug.LogError("땅을 감지하지 못하는 버그");
return;
}
BasicSetting();
ShowIndicator();
_startDistance = _raycastHit.distance;
}
var startDistance = float.PositiveInfinity;
while (!_isGrounded)
private void Update()
{
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
{
if (!Physics.Raycast(transform.position, Vector3.down, out var hit, 10f, _groundLayer)) continue;
if (float.IsPositiveInfinity(startDistance))
{
startDistance = hit.distance;
}
Debug.LogError("땅을 감지하지 못하는 버그");
return;
}
_isGrounded = _raycastHit.distance <= _checkDistance;
if (!_isGrounded)
{
if (_isUsingIndicator && _indicator)
{
var fillValue = Mathf.Lerp(1f, 0f, hit.distance / startDistance);
var fillValue = Mathf.Lerp(1f, 0f, _raycastHit.distance / _startDistance);
_indicator.material.SetFloat(_fillHash, fillValue);
}
_isGrounded = hit.distance <= _checkDistance;
yield return null;
}
_indicator.material.SetFloat(_fillHash, 1f);
HideIndicator();
if (_rigidbody)
else if (_isGrounded && !_isAttacked)
{
_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;
_indicator.material.SetFloat(_fillHash, 1f);
HideIndicator();
iDamageable.TakeDamage(_attackDamage);
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);
Die();
}
_isAttacked = true;
}
}