Ejemplo n.º 1
0
        IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            characterMovement.GetCapsuleCollider().enabled = false; // Disabling the collider so when the enemy dies the player can path throgh thier dead bodys and not to have a glitch.
            animator.SetTrigger(DEATH_TRIGGER);
            var playerComponent = GetComponent <PlayerControl>();

            if (deathSounds.Length != 0)
            {
                audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
                audioSource.Play();
            }
            characterMovement.GetNavMeshAgent().speed = 0;
            //yield return new WaitForSecondsRealtime(audioSource.clip.length);
            yield return(null);

            if (playerComponent && playerComponent.isActiveAndEnabled) // relying on Lazy Evaluation (Google if you need help)
            {
                FindObjectOfType <SavingWrapper>().DeleteSave();
                SceneManager.LoadSceneAsync(0);
                //SceneManager.LoadScene(0); // TODO check for scene Error
            }
            else // Assume is enemy for now, reconsider other NPCs Later
            {
                characterMovement.GetNavMeshAgent().speed = 0;
                //DestroyObject(gameObject, deathVanishSeconds + audioSource.clip.length);
                //Destroy(gameObject, deathVanishSeconds + audioSource.clip.length);
            }
        }
Ejemplo n.º 2
0
        void KillCharacterWithoutDestroy()
        {
            Character character = GetComponent <Character>();

            character.Kill();
            character.GetCapsuleCollider().enabled = false;
            GetComponent <Animator>().SetTrigger(DEATH_TRIGGER);
            gameObject.SetActive(false); // Getting around the idea of saving each destroied object. instead we set it to active so it won't be renderd.
        }