Пример #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);
            }
        }
Пример #2
0
        private IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)
            {
                if (deathSounds.Length > 0)
                {
                    source.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
                    source.Play();
                    yield return(new WaitForSeconds(source.clip.length));
                }

                SceneManager.LoadScene(0);
            }
            else
            {
                if (deathSounds.Length > 0)
                {
                    source.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
                    source.Play();
                    yield return(new WaitForSeconds(source.clip.length));
                }

                DestroyObject(gameObject, deathVanishSeconds);
            }
        }
Пример #3
0
        IEnumerator KillCharacter()
        {
            characterMovement.Kill(); // tell character movement that the dying is happening
            animator.SetTrigger(DEATH_TRIGGER);

            audioSource.clip = deathSounds[Random.Range(0, deathSounds.Length)];
            audioSource.Play(); // override any existing sound
            yield return(new WaitForSecondsRealtime(audioSource.clip.length));

            //yield return new WaitForSecondsRealtime(0);

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled) // relying on lazy evaluation
            {
                SceneManager.LoadScene(0);                             // reload scene
            }
            else
            {
                if (!isDestroyed)
                {
                    Debug.Log("destroy char");
                    Destroy(gameObject, deathVanishSeconds);
                    isDestroyed = true;
                }
            }
        }
Пример #4
0
        IEnumerator KillCharacter()
        {
            if (character != null)
            {
                character.Kill();
                animator.SetTrigger(DEATH_TRIGGER);
            }

            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play();

            Destroy(healthSlider.gameObject);
            yield return(new WaitForSeconds(audioSource.clip.length));

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent)
            {
                //SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
            else
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #5
0
        IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            var playerComponent = GetComponent <PlayerControl>();

            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play();
            animator.SetTrigger(Constants.DEATH_TRIGGER);

            if (playerComponent)
            {
                //to prevent the player move when is dead and the uses clicks on terrain
                FindObjectOfType <CameraRaycaster>().enabled = false;
            }
            else
            {
                //to prevent the enemy to follow the player while he is dead
                GetComponent <EnemyAI>().enabled = false;
            }
            GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
            Destroy(GetComponent <NavMeshAgent>());
            Destroy(GetComponent <CapsuleCollider>());
            Destroy(GetComponent <Rigidbody>());

            yield return(new WaitForSecondsRealtime(audioSource.clip.length));

            if (playerComponent && playerComponent.isActiveAndEnabled)
            {
                SceneManager.LoadScene(0);
            }
            else
            {
                StartCoroutine(FadeTo(0, deathVanishSeconds));
            }
        }
Пример #6
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.
        }
Пример #7
0
        IEnumerator KillCharacter()
        {
            characterMovment.Kill();
            animator.SetTrigger(DEATH_TRIGER);

            var playerComponent = GetComponent <PlayerControl>();

            PlayDeathSound();

            if (playerComponent && playerComponent.isActiveAndEnabled)
            {
                yield return(new WaitForSecondsRealtime(audioSource.clip.length + 1f));

                SceneManager.LoadScene(0);
            }
            else
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #8
0
        IEnumerator KillCharacter()
        {
            StopAllCoroutines();
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);
            var playerComponent = GetComponent <PlayerMovement>();

            if (playerComponent && playerComponent.isActiveAndEnabled) // relying on lazy evaluation
            {
                audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
                audioSource.Play(); // overrind any existing sounds
                yield return(new WaitForSecondsRealtime(audioSource.clip.length));

                SceneManager.LoadScene(0);
            }
            else // assume is enemy fr now, reconsider on other NPCs
            {
                DestroyObject(gameObject, deathVanishSeconds);
            }
        }
Пример #9
0
        IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play();
            yield return(new WaitForSecondsRealtime(audioSource.clip.length));

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)   // Lazy evaluation
            {
                SceneManager.LoadScene(0);
            }
            else     // Assuming Enemy for now, reconsider for other NPCs
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #10
0
        IEnumerator KillCharacter() // Use coroutine when methods have to be time based
        {
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play(); // override any existing sounds
            yield return(new WaitForSecondsRealtime(audioSource.clip.length));

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)
            {
                SceneManager.LoadScene(0);
            }
            else // assume is enemy for now, reconsider on other NPCs
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #11
0
        IEnumerator KillCharacter()
        {
            character.Kill();
            animator.SetTrigger(DEATH_TRIGGER);
            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play();
            yield return(new WaitForSecondsRealtime(audioSource.clip.length)); // TODO: use audio clip lenght

            var player = GetComponent <PlayerControl>();

            if (player && player.isActiveAndEnabled)
            {
                SceneManager.LoadScene(0);
            }
            else
            {
                // is enemy, do something to kill them
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #12
0
        IEnumerator KillCharacter()
        {
            //StopAllCoroutines();
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);
            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)
            {
                audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
                audioSource.Play();
                yield return(new WaitForSecondsRealtime(audioSource.clip.length + 1f));

                SceneManager.LoadScene(0);
            }
            else
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #13
0
        IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);
            var playerComponent = GetComponent <PlayerControl>();

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

            if (playerComponent && playerComponent.isActiveAndEnabled) // relying on Lazy Evaluation (Google if you need help)
            {
                SceneManager.LoadScene(0);
            }
            else // Assume is enemy for now, reconsider other NPCs Later
            {
                characterMovement.GetNavMeshAgent().speed = 0;
                DestroyObject(gameObject, deathVanishSeconds + audioSource.clip.length);
            }
        }
        IEnumerator KillCharacter()
        {
            characterMovement.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            audioSource.clip = deathSounds[UnityEngine.Random.Range(0, deathSounds.Length)];
            audioSource.Play(); // pverride any existing sounds (not OneShot)
            yield return(new WaitForSecondsRealtime(audioSource.clip.length));

            var playerComponent = GetComponent <PlayerControl>();

            // if it is a Player
            if (playerComponent && playerComponent.isActiveAndEnabled) // lazy evaluation
            {
                SceneManager.LoadScene(0);
            }
            else
            {
                DestroyObject(gameObject, deathVanishSeconds);
            }
        }
Пример #15
0
        private IEnumerator KillCharacter()
        {
            _character.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            float deathLength = PlayRandomDeathSound();

            yield return(new WaitForSecondsRealtime(deathLength));

            // if we are dealing with a _playerControl
            PlayerControl playerControlComponent = GetComponent <PlayerControl>();

            if (playerControlComponent && playerControlComponent.isActiveAndEnabled)
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
            else                 // assume enemy
            {
                DestroyObject(gameObject, deathVanishSeconds);
            }
        }
Пример #16
0
        IEnumerator KillCharacter()
        {
            character.Kill();

            anim.SetTrigger(DEATH_TRIGGER);

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)            // lazy evaluation
            {
                PlayDeathSound();

                // wait reload the scene or death screen SceneManager.something
                yield return(new WaitForSecondsRealtime(audioSource.clip.length));

                SceneManager.LoadScene(0);
            }
            else
            {
                Destroy(gameObject, deathVanishSeconds);
            }
        }
Пример #17
0
        IEnumerator KillCharacter()
        {
            isAlive = false;
            StopAllCoroutines();
            character.Kill();
            animator.SetTrigger(DEATH_TRIGGER);

            var playerComponent = GetComponent <PlayerControl>();

            if (playerComponent && playerComponent.isActiveAndEnabled)//If it is the player.
            {
                audioSource.clip  = deathSounds[(int)UnityEngine.Random.Range(0, deathSounds.Length)];
                audioSource.pitch = 1;
                audioSource.Play();
                float duration = animator.GetCurrentAnimatorClipInfo(0).Length;
                yield return(new WaitForSecondsRealtime(duration + 2)); //Animation Length;

                SceneManager.LoadScene(0);
            }
            else //Assume is enemy for now Reconsiderd other NPCs.
            {
                Destroy(gameObject, deathBanishSeconds);
            }
        }