PitchChange of EnemyDeath Randomized

dev-ali
Ali Sharoz 2 months ago
parent 92b9a98bc3
commit b11b550b05

@ -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<float> 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<MeshRenderer>(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<Rigidbody>();
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;
}

@ -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

Loading…
Cancel
Save