#19 Rockfall 바닥 뚫는 버그 및 무한루프 버그 수정
+ DamageableProps Enable()함수에 Max체력으로 변경하는 로직 추거 Closes #19
This commit is contained in:
parent
1ee1df12dd
commit
d76915283a
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using BlueWater.Audios;
|
using BlueWater.Audios;
|
||||||
using BlueWater.Interfaces;
|
using BlueWater.Interfaces;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
@ -23,6 +24,11 @@ namespace BlueWater
|
|||||||
|
|
||||||
protected Transform SpawnLocation;
|
protected Transform SpawnLocation;
|
||||||
|
|
||||||
|
protected virtual void OnEnable()
|
||||||
|
{
|
||||||
|
SetCurrentHealthPoint(MaxHealthPoint);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
|
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
|
||||||
{
|
{
|
||||||
CurrentHealthPoint = changedHealthPoint;
|
CurrentHealthPoint = changedHealthPoint;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using BlueWater.Audios;
|
using BlueWater.Audios;
|
||||||
using BlueWater.Interfaces;
|
using BlueWater.Interfaces;
|
||||||
@ -12,9 +11,6 @@ namespace BlueWater
|
|||||||
public class Rockfall : DamageableProps
|
public class Rockfall : DamageableProps
|
||||||
{
|
{
|
||||||
[Title("컴포넌트")]
|
[Title("컴포넌트")]
|
||||||
[SerializeField]
|
|
||||||
private Rigidbody _rigidbody;
|
|
||||||
|
|
||||||
[SerializeField, Required]
|
[SerializeField, Required]
|
||||||
private SphereCollider _sphereCollider;
|
private SphereCollider _sphereCollider;
|
||||||
|
|
||||||
@ -32,8 +28,8 @@ namespace BlueWater
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private LayerMask _groundLayer;
|
private LayerMask _groundLayer;
|
||||||
|
|
||||||
[SerializeField, Range(0f, 1f)]
|
[SerializeField, Range(0f, 5f)]
|
||||||
private float _checkDistance = 0.1f;
|
private float _fallTime = 1f;
|
||||||
|
|
||||||
[SerializeField, Range(0, 5)]
|
[SerializeField, Range(0, 5)]
|
||||||
private int _attackDamage = 1;
|
private int _attackDamage = 1;
|
||||||
@ -45,88 +41,83 @@ namespace BlueWater
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private ParticleSystem _groundCrashParticle;
|
private ParticleSystem _groundCrashParticle;
|
||||||
|
|
||||||
private Collider[] _hitColliders = new Collider[4];
|
private Collider[] _hitColliders;
|
||||||
private RaycastHit _raycastHit;
|
private RaycastHit _raycastHit;
|
||||||
private float _startDistance = float.PositiveInfinity;
|
private Vector3 _startPosition;
|
||||||
private bool _isGrounded;
|
private Vector3 _endPosition;
|
||||||
private bool _isAttacked;
|
private bool _isAttacked;
|
||||||
|
|
||||||
// Hashes
|
// Hashes
|
||||||
private static readonly int _fillHash = Shader.PropertyToID("_Fill");
|
private static readonly int _fillHash = Shader.PropertyToID("_Fill");
|
||||||
|
|
||||||
private void OnDrawGizmos()
|
private IEnumerator Start()
|
||||||
{
|
|
||||||
Debug.DrawRay(transform.position, Vector3.down * _checkDistance, _isGrounded ? Color.blue : Color.red);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
{
|
||||||
_sphereCollider.enabled = false;
|
_sphereCollider.enabled = false;
|
||||||
|
_startPosition = transform.position;
|
||||||
SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation;
|
SpawnLocation = MapManager.Instance.SandMoleMapController.ParticleInstantiateLocation;
|
||||||
|
_hitColliders = new Collider[4];
|
||||||
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
|
|
||||||
{
|
|
||||||
Debug.LogError("땅을 감지하지 못하는 버그");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BasicSetting();
|
BasicSetting();
|
||||||
ShowIndicator();
|
|
||||||
_startDistance = _raycastHit.distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FixedUpdate()
|
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 50f, _groundLayer))
|
||||||
{
|
|
||||||
if (!Physics.Raycast(transform.position, Vector3.down, out _raycastHit, 10f, _groundLayer))
|
|
||||||
{
|
{
|
||||||
Debug.LogError("땅을 감지하지 못하는 버그");
|
Debug.LogError("땅을 감지하지 못하는 버그");
|
||||||
return;
|
yield break;
|
||||||
}
|
}
|
||||||
_isGrounded = _raycastHit.distance <= _checkDistance;
|
_endPosition = _raycastHit.point;
|
||||||
|
|
||||||
if (!_isGrounded)
|
ShowIndicator();
|
||||||
|
var elapsedTime = 0f;
|
||||||
|
while (elapsedTime <= _fallTime)
|
||||||
{
|
{
|
||||||
|
var time = elapsedTime / _fallTime;
|
||||||
if (_isUsingIndicator && _indicator)
|
if (_isUsingIndicator && _indicator)
|
||||||
{
|
{
|
||||||
var fillValue = Mathf.Lerp(1f, 0f, _raycastHit.distance / _startDistance);
|
var fillValue = Mathf.Lerp(0f, 1f, time);
|
||||||
_indicator.material.SetFloat(_fillHash, fillValue);
|
_indicator.material.SetFloat(_fillHash, fillValue);
|
||||||
}
|
}
|
||||||
|
transform.position = Vector3.Lerp(_startPosition, _endPosition, time);
|
||||||
|
elapsedTime += Time.deltaTime;
|
||||||
|
|
||||||
|
yield return null;
|
||||||
}
|
}
|
||||||
else if (_isGrounded && !_isAttacked)
|
|
||||||
|
_indicator.material.SetFloat(_fillHash, 1f);
|
||||||
|
HideIndicator();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(_groundCrashSfxName))
|
||||||
{
|
{
|
||||||
_indicator.material.SetFloat(_fillHash, 1f);
|
AudioManager.Instance.PlaySfx(_groundCrashSfxName);
|
||||||
HideIndicator();
|
}
|
||||||
|
|
||||||
if (_rigidbody)
|
if (_groundCrashParticle)
|
||||||
|
{
|
||||||
|
if (!SpawnLocation)
|
||||||
{
|
{
|
||||||
_rigidbody.isKinematic = true;
|
Debug.LogError("파티클 위치 생성 오류");
|
||||||
|
yield break;
|
||||||
}
|
}
|
||||||
_sphereCollider.enabled = true;
|
Instantiate(_groundCrashParticle, transform.position, Quaternion.identity, SpawnLocation);
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(_groundCrashSfxName))
|
var hitCount = Physics.OverlapSphereNonAlloc(_sphereCollider.bounds.center, _sphereCollider.radius,
|
||||||
{
|
_hitColliders, _targetLayer, QueryTriggerInteraction.Collide);
|
||||||
AudioManager.Instance.PlaySfx(_groundCrashSfxName);
|
for (var i = 0; i < hitCount; i++)
|
||||||
}
|
{
|
||||||
|
var hitCollider = _hitColliders[i];
|
||||||
if (_groundCrashParticle && SpawnLocation)
|
var iDamageable = hitCollider.GetComponentInParent<IDamageable>();
|
||||||
{
|
if (iDamageable == null || !iDamageable.CanDamage()) continue;
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
iDamageable.TakeDamage(_attackDamage);
|
||||||
_isAttacked = true;
|
_isAttacked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isAttacked)
|
||||||
|
{
|
||||||
|
Die();
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sphereCollider.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BasicSetting()
|
private void BasicSetting()
|
||||||
|
@ -68,6 +68,14 @@ PrefabInstance:
|
|||||||
propertyPath: m_ExcludeLayers.m_Bits
|
propertyPath: m_ExcludeLayers.m_Bits
|
||||||
value: 1024
|
value: 1024
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
||||||
|
propertyPath: m_UseGravity
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
||||||
|
propertyPath: m_IsKinematic
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 3580758810857167321, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
- target: {fileID: 3580758810857167321, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
||||||
propertyPath: m_Sprite
|
propertyPath: m_Sprite
|
||||||
value:
|
value:
|
||||||
@ -164,7 +172,6 @@ MonoBehaviour:
|
|||||||
<CurrentHealthPoint>k__BackingField: 0
|
<CurrentHealthPoint>k__BackingField: 0
|
||||||
_dieSfxName:
|
_dieSfxName:
|
||||||
_dieParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
|
_dieParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
|
||||||
_rigidbody: {fileID: 1838738275417183443}
|
|
||||||
_sphereCollider: {fileID: 2971964863692897937}
|
_sphereCollider: {fileID: 2971964863692897937}
|
||||||
_indicator: {fileID: 6370181286260610806}
|
_indicator: {fileID: 6370181286260610806}
|
||||||
_isUsingIndicator: 1
|
_isUsingIndicator: 1
|
||||||
@ -174,15 +181,10 @@ MonoBehaviour:
|
|||||||
_groundLayer:
|
_groundLayer:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 64
|
m_Bits: 64
|
||||||
_checkDistance: 0.1
|
_fallTime: 1
|
||||||
_attackDamage: 1
|
_attackDamage: 1
|
||||||
_groundCrashSfxName:
|
_groundCrashSfxName:
|
||||||
_groundCrashParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
|
_groundCrashParticle: {fileID: 19826678, guid: 660dfd0ccf26cbf489a7556236949683, type: 3}
|
||||||
--- !u!54 &1838738275417183443 stripped
|
|
||||||
Rigidbody:
|
|
||||||
m_CorrespondingSourceObject: {fileID: 2892108968249248585, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
|
||||||
m_PrefabInstance: {fileID: 3577643095578124186}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
--- !u!135 &2971964863692897937 stripped
|
--- !u!135 &2971964863692897937 stripped
|
||||||
SphereCollider:
|
SphereCollider:
|
||||||
m_CorrespondingSourceObject: {fileID: 1772409705626034443, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
m_CorrespondingSourceObject: {fileID: 1772409705626034443, guid: bfc5c806b2fa3ba40850df302d3db0b7, type: 3}
|
||||||
|
Loading…
Reference in New Issue
Block a user