Example #1
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
            {
                if (CurrentCompanions < TotalAllowedCompanions)
                {
                    //Spawn our AI using the Emerald Object Pool system
                    Vector3 SpawnPosition = transform.position + transform.forward * 5 + (Random.insideUnitSphere * 2);
                    SpawnPosition.y = transform.position.y;
                    GameObject SpawnedAI = EmeraldAIObjectPool.Spawn(CompanionAIObject, SpawnPosition, Quaternion.identity);

                    //Set an event on the created AI to remove the AI on death
                    SpawnedAI.GetComponent <EmeraldAISystem>().DeathEvent.AddListener(() => { RemoveAI(); });

                    //Add the spawned AI to the total amount of currently spawn AI
                    CurrentCompanions++;
                }
            }

            /*
             * if (Input.GetKeyDown(KeyCode.H) && GameObject.Find("Fallen Guardian (Companion)") != null)
             * {
             *  GameObject.Find("Fallen Guardian (Companion)").GetComponent<EmeraldAISystem>().EmeraldEventsManagerComponent.StopFollowing();
             * }
             * if (Input.GetKeyDown(KeyCode.J) && GameObject.Find("Fallen Guardian (Companion)") != null)
             * {
             *  GameObject.Find("Fallen Guardian (Companion)").GetComponent<EmeraldAISystem>().EmeraldEventsManagerComponent.ResumeFollowing();
             * }
             */
        }
Example #2
0
        void Update()
        {
            if (!calculatedHit)
            {
                attackTimer += Time.deltaTime;
            }

            attackSoundTimer += Time.deltaTime;

            if (calculatedHit)
            {
                timer += Time.deltaTime;

                if (timer >= attackDelay)
                {
                    if (hit.collider != null && hit.collider.gameObject.GetComponent <EmeraldAISystem>() != null)
                    {
                        if (HitTags.Contains(hit.collider.gameObject.tag))
                        {
                            if (useBloodEffect)
                            {
                                GameObject SpawnedEffect = EmeraldAIObjectPool.Spawn(bloodEffect, hit.point, Quaternion.identity);
                                SpawnedEffect.transform.parent = transform.root;
                            }

                            if (!audioDisabled && useImpactSounds)
                            {
                                _audioSource.PlayOneShot(impactSounds[Random.Range(0, impactSounds.Count)]);
                            }

                            hit.collider.gameObject.GetComponent <EmeraldAISystem>().Damage(damage, EmeraldAISystem.TargetType.Player, transform.root, 200);
                        }
                    }

                    if (hit.collider != null && hit.collider.tag == "Untagged" || hit.collider != null && hit.collider.tag == "Terrain")
                    {
                        if (hitOtherEffect != null && useHitEffect)
                        {
                            GameObject SpawnedEffect = EmeraldAIObjectPool.Spawn(hitOtherEffect, hit.point, Quaternion.LookRotation(hit.normal));
                            SpawnedEffect.transform.parent = transform.root;
                        }

                        if (!audioDisabled && useImpactOtherSounds)
                        {
                            _audioSource.PlayOneShot(impactOtherSounds[Random.Range(0, impactOtherSounds.Count)]);
                        }
                    }

                    damage = Random.Range(MinDamage, MaxDamage);

                    attackTimer   = 0;
                    calculatedHit = false;
                    timer         = 0;
                }
            }
        }