// OnDie protected virtual void OnDie() { if (regeneration) { StopCoroutine("StartRegeneration"); } Vector3 nativePos = transform.position; nativePos.y += .15f; System.Action callSpawning = () => { foreach (GameObject deathObj in deathObjects) { if (deathObj != null) { (Instantiate(deathObj, nativePos, Random.rotation) as GameObject) .MoveToCache() .Send("SetOwner", lastDamage.owner) .Send("OnSpawn"); } } foreach (Pickup drop in deathDrops) { if (drop != null) { Vector3 randomPos = nativePos; randomPos.y += Random.value; randomPos.x += Random.Range(-1, 1f); randomPos.z += Random.Range(-1, 1f); drop.SpawnCopy(randomPos, Random.rotation) .MoveToCache() .Send("OnSpawn"); if (dropOnlyOnePickup) { break; } } } }; OnDead.Invoke(); if (spawnObjectsDelay > 0) { this.RunAction(callSpawning, spawnObjectsDelay); } else { callSpawning.Invoke(); } Respawner.StartRespawn(gameObject, destroyBodyDelay); }
// Destroy It private void DestroyIt(bool playSound = true) { if (playSound) { Utils.Audio.PlayClipAtPoint(pickupSound, m_Transform.position); } Respawner.StartRespawn(gameObject); }