Exemplo n.º 1
0
 /// <summary>
 /// Occurs when the projectile collides with another collider.
 /// </summary>
 /// <param name="c">Collider that caused the collision event.</param>
 void OnCollisionEnter(Collision c)
 {
     if (((HeatSeekLayers.value | GlobalFuncs.targetingLayerMaskCollision.value) & 1 << c.gameObject.layer) == 1 << c.gameObject.layer)
     {  // valid collide target
         bool bFound = false;
         if (ChainEffectCount > 0)
         {  // chain spell to another target?
             List <Transform> listTargetsInRange = GlobalFuncs.FindAllTargetsWithinRange(transform.position, HeatSeekRange, HeatSeekLayers, HeatSeekTags, true, 1.5f, true);
             if (listTargetsInRange.Count > 0)
             {                                                       // found more in range
                 sChainedToAlready += "-" + c.gameObject.name + "-"; // unique character names required, append name of current collision
                 foreach (Transform t in listTargetsInRange)
                 {
                     if (!sChainedToAlready.Contains("-" + t.gameObject.name + "-"))
                     {                                                                                                                                         // found new target
                         DestroyGameObjectAndSpawn md = GetComponent <DestroyGameObjectAndSpawn>();                                                            //  attempt gray destroy n spawn
                         if (md)
                         {                                                                                                                                     // found
                             md.enabled = false;                                                                                                               // disable it
                         }
                         MagicPool_Return mr = GetComponent <MagicPool_Return>();                                                                              // attempt get the pool return component
                         if (mr)
                         {                                                                                                                                     // found
                             mr.enabled = false;                                                                                                               // disable
                             mr.enabled = true;                                                                                                                // re enable, resetting the count down
                         }
                         tSpellTarget  = t;                                                                                                                    // re target the projectile
                         v3SpellTarget = tSpellTarget.position;                                                                                                // update position of the transform
                         FollowTarget  = true;                                                                                                                 // ensure moving target is followed
                         bFound        = true;                                                                                                                 // flag don't destroy
                         if (ParticlesOnCollision.Count > 0)
                         {                                                                                                                                     // has spawns?
                             StartCoroutine(GlobalFuncs.SpawnAllDelayed(ParticlesOnCollision, SpawnDelay, NoneSequential, transform, null, 0, false, Target)); // spawn all but dont kill the projectile
                         }
                         ChainEffectCount -= 1;                                                                                                                // lower the chain count
                         break;                                                                                                                                // work complete
                     }
                 }
             }
         }
         if (!bFound)
         {                                                                                                                                                             // run out of chain-able enemies or chaining not enabled
             if (ParticlesOnCollision.Count > 0)
             {                                                                                                                                                         // has spawns?
                 if (gameObject.activeInHierarchy)
                 {                                                                                                                                                     // failsafe, not already returned to the pool
                     StartCoroutine(GlobalFuncs.SpawnAllDelayed(ParticlesOnCollision, SpawnDelay, NoneSequential, transform, gameObject, iPoolSlotID, false, Target)); // spawn all then kill the projectile
                 }
             }
             else
             {
                 GlobalFuncs.ReturnToThePoolOrDestroy(iPoolSlotID, gameObject);  // kill or return projectile to the pool
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Apply the spawn settings to the instantiated game object
        /// </summary>
        /// <param name="Instance"></param>
        /// <param name="PhysicsInstance"></param>
        protected void SetSpawnOptions(ref GameObject Instance, PhysicsOptions PhysicsInstance)
        {
            Instance.SetActive(false);                                                                         // ensure not active
            if (!KeepParent)                                                                                   // some spells such as teleport DO NOT want this setting
            {
                Instance.transform.parent = null;                                                              // clear
            }
            if (Offset != Vector3.zero)                                                                        // offset needed?
            {
                Instance.transform.position = Instance.transform.position + Offset;                            // add in the offset
            }
            if (Angle != Vector3.zero)                                                                         // angular offset needed?
            {
                Instance.transform.localRotation = Quaternion.Euler(Angle) * Instance.transform.localRotation; // alter the angle
            }
            RandomSphere.Apply(ref Instance);                                                                  // spawn randomly within sphere radius?
            RandomRotate.Apply(ref Instance);                                                                  // apply random rotation to the enabled axis's
            PhysicsInstance.Apply(Instance, Target);                                                           // explode with force?
            if (CheckSpaceIsEmpty(Instance))                                                                   // spawned within an empty space checked ok?
            {
                if (DestructionTimeOut > 0)                                                                    // max length of instance enabled
                {
                    if (GlobalFuncs.MAGICAL_POOL && !DoNotPool)                                                // pool enabled?
                    {
                        MagicPool_Return mr = Instance.GetComponent <MagicPool_Return>();                      // attempt get the pool return component
                        mr.Delay = DestructionTimeOut;                                                         // set the return to pool timeout
                    }
                    else
                    {
                        UnityEngine.Object.Destroy(Instance, DestructionTimeOut);  // set to destroy in 5,4,3...
                    }
                }
            }
            else  // space not empty
            {
                GlobalFuncs.ReturnToThePoolOrDestroy(PoolSlotId, Instance);  // send back to the pool (if enabled)
            }

            // all options set activate
            Instance.SetActive(true);
        }  // set the spawn options