diff --git a/Assets/3rd/D2D_Scripts/Gameplay/Health/Health.cs b/Assets/3rd/D2D_Scripts/Gameplay/Health/Health.cs index b8000168..15265dc7 100644 --- a/Assets/3rd/D2D_Scripts/Gameplay/Health/Health.cs +++ b/Assets/3rd/D2D_Scripts/Gameplay/Health/Health.cs @@ -14,23 +14,23 @@ namespace D2D.Gameplay [Header("Hit Flash")] [SerializeField] private Gradient gradient; private Color originalColor; - + [SerializeField] private float _maxPoints; [SerializeField] private HealthData _healthData; [SerializeField] private SkinnedMeshRenderer _meshRenderer; - + [SerializeField] private GameObject _hitEffect; [SerializeField] private GameObject _deathEffect; - + [SerializeField] private bool _isGrayFadeout; [SerializeField] private bool _isPlayer; - + public event Action Died; public event Action Damaged; public event Action PointsChanged; private Tween flashTween; - + public GameObject LastAttacker { get; private set; } private void OnEnable() @@ -59,11 +59,11 @@ namespace D2D.Gameplay private set => _maxPoints = value; get { - if (!isHealthDataMode) + if (!isHealthDataMode) return _maxPoints; - + // If health data: - + if (_healthData == null) throw new Exception("Health data is not attached!"); @@ -132,7 +132,7 @@ namespace D2D.Gameplay } else { - InitiateDeathSequence(); + InitiateDeathSequence(); } } } @@ -155,7 +155,7 @@ namespace D2D.Gameplay InitiateDeathSequence(); } } - + IEnumerator DeathCoroutine() { yield return new WaitForSeconds(6f); @@ -167,9 +167,14 @@ namespace D2D.Gameplay private void InitiateDeathSequence() { Died?.Invoke(); - if(!_isPlayer) + if (!_isPlayer) { - _enemySpawn.EnemyDeathAudio.Play(); + float pitch = UnityEngine.Random.Range(0.8f, 1.2f); + if (_enemySpawn.EnemyDeathAudio != null) + { + _enemySpawn.EnemyDeathAudio.pitch = pitch; + _enemySpawn.EnemyDeathAudio.Play(); + } HapticPatterns.PlayPreset(HapticPatterns.PresetType.MediumImpact); } if (_isGrayFadeout) @@ -181,13 +186,13 @@ namespace D2D.Gameplay ImmediateDeath(); } } - + private void ImmediateDeath() { Spawn(_deathEffect); Destroy(gameObject); } - + private void GrayFadeoutDeath() { this.ChildrenGets(renderer => @@ -205,13 +210,13 @@ namespace D2D.Gameplay material.DOColor(_gameData.grayDeathColor, _gameData.grayDeathDuration); }); }); - + _gameData.grayCorpseLifetime.AfterCall(() => transform.DOScale(0, .3f).onComplete += ImmediateDeath); /*var rb = this.Get(); rb.isKinematic = false; rb.freezeRotation = false;*/ - + /*.1f.AfterCall(() => rb.angularVelocity *= DMath.Random(1, 2f));*/ } @@ -219,8 +224,8 @@ namespace D2D.Gameplay { if (prefab == null) return; - - GameObject instance = Instantiate(prefab, transform.position, + + GameObject instance = Instantiate(prefab, transform.position, transform.rotation, null); Destroy(instance, 2f); @@ -231,7 +236,7 @@ namespace D2D.Gameplay if (healPoints <= 0) throw new Exception("Heal points should be positive!"); - CurrentPoints = Math.Min(CurrentPoints+healPoints, _maxPoints); + CurrentPoints = Math.Min(CurrentPoints + healPoints, _maxPoints); } public void SetMaxPoints(float newMaxPoints, bool needRefill = false) @@ -240,7 +245,7 @@ namespace D2D.Gameplay throw new Exception("Max points should be positive!"); MaxPoints = newMaxPoints; - + if (needRefill) CurrentPoints = MaxPoints; } diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index 6524f741..bb03ab7b 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -189447,7 +189447,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1984993047125568119, guid: 2afb0c0b1e9834310869cb2f0c994844, type: 3} propertyPath: m_AnchoredPosition.y - value: 2.2411957 + value: 2.241211 objectReference: {fileID: 0} - target: {fileID: 1991915019850540130, guid: 2afb0c0b1e9834310869cb2f0c994844, type: 3} propertyPath: m_AnchorMax.x