Ejemplo n.º 1
0
        IEnumerator Despawn()
        {
            yield return(new WaitForSeconds(Seconds));

            UniStormPool.Despawn(this.gameObject);
        }
Ejemplo n.º 2
0
        public void CreateLightningStrike()
        {
            RaycastHit hit;

            int Roll = Random.Range(1, 101);

            if (Roll <= GroundStrikeOdds)
            {
                RaycastDistance = 250;
            }
            else
            {
                RaycastDistance = 0;
            }

            if (!ObjectDetected)
            {
                HitPosition = transform.position;
            }

            if (Physics.Raycast(new Vector3(HitPosition.x, HitPosition.y + 40, HitPosition.z), -transform.up, out hit, RaycastDistance, DetectionLayerMask))
            {
                Vector3 pos = hit.point;
                LightningGenerated = true;
                UniStormSystem.Instance.LightningStruckObject = HitObject;

                if (hit.collider.GetComponent <Terrain>() != null && !ObjectDetected)
                {
                    HitPosition = new Vector3(pos.x, hit.collider.GetComponent <Terrain>().SampleHeight(hit.point) + 0.5f, pos.z);
                }
                else
                {
                    HitPosition = new Vector3(HitPosition.x, pos.y + 0.5f, HitPosition.z);
                }

                if (!PlayerDetected && !EmeraldAIAgentDetected)
                {
                    //If our hit object contains a LightningFireTag, start a fire.
                    if (LightningFireTags.Contains(hit.collider.tag))
                    {
                        GameObject HitEffect = UniStormPool.Spawn(LightningStrikeFire, HitPosition, Quaternion.identity);
                        HitEffect.transform.SetParent(hit.collider.transform);
                    }

                    UniStormPool.Spawn(LightningStrikeEffect, HitPosition, Quaternion.identity);
                    UniStormSystem.Instance.OnLightningStrikeObjectEvent.Invoke();
                }
                else if (PlayerDetected)
                {
                    if (LightningFireTags.Contains(hit.collider.tag))
                    {
                        UniStormPool.Spawn(LightningStrikeFire, HitPosition, Quaternion.identity);
                    }

                    UniStormPool.Spawn(LightningStrikeEffect, HitPosition, Quaternion.identity);
                    UniStormSystem.Instance.OnLightningStrikePlayerEvent.Invoke();
                }
                else if (EmeraldAIAgentDetected)
                {
#if EMERALD_AI_PRESENT
                    if (UniStormSystem.Instance.LightningStrikesEmeraldAI == UniStormSystem.EnableFeature.Enabled)
                    {
                        HitPosition = HitAgent.transform.position;
                        UniStormSystem.Instance.LightningStruckObject = HitAgent;
                        if (HitAgent.GetComponent <EmeraldAI.EmeraldAISystem>() != null)
                        {
                            HitAgent.GetComponent <EmeraldAI.EmeraldAISystem>().Damage(EmeraldAILightningDamage, EmeraldAI.EmeraldAISystem.TargetType.Player, HitAgent.transform, EmeraldAIRagdollForce);
                        }
                    }

                    //If our hit object contains a LightningFireTag, start a fire.
                    if (LightningFireTags.Contains(hit.collider.tag))
                    {
                        GameObject HitEffect = UniStormPool.Spawn(LightningStrikeFire, HitAgent.transform.position + new Vector3(0, -1.7f, 0), Quaternion.identity);
                        HitEffect.transform.SetParent(hit.collider.transform);
                    }

                    UniStormPool.Spawn(LightningStrikeEffect, HitAgent.transform.position, Quaternion.identity);
                    UniStormSystem.Instance.OnLightningStrikeObjectEvent.Invoke();
                    EmeraldAIAgentDetected = false;
                    StartCoroutine("ResetDelay");
#endif
                }

                LightningGenerated     = false;
                ObjectDetected         = false;
                PlayerDetected         = false;
                EmeraldAIAgentDetected = false;
                HitObject = null;
                HitAgent  = null;
            }
        }