Example #1
0
        IEnumerator     StunPlayers(PlayerShip vPS1, PlayerShip vPS2, float vTime) //CoRoutine to stun wait then unstun, check https://docs.unity3d.com/Manual/Coroutines.html
        {
            vPS1.mStunned = true;                                                  //This will run right away
            vPS2.mStunned = vPS1.mStunned;
            yield   return(new     WaitForSeconds(vTime));                         //This will give suspend this CoRoutine for a period of time

            vPS1.mStunned = false;                                                 //When time is up code will keep executing here
            vPS2.mStunned = vPS1.mStunned;
        }
Example #2
0
 public override void    ProcessHit(Entity vOther) //As this is only called from a command , it will also process on Server
 {
     Assert.IsTrue(isServer);                      //Must run on server, Assert is a debug feature which is removed on non debug builds See:https://docs.unity3d.com/ScriptReference/Assertions.Assert.html
     if (vOther.EType == EntityType.Bullet)        //Destroy bullet
     {
         Bullet     tBullet = (Bullet)vOther;      //We have a bullet, find who fired it
         PlayerShip tPlayer = FindServerEntity(tBullet.mPlayerID) as PlayerShip;
         tPlayer.GiveScore(10);                    //Give score to player who shot us
         Destroy(vOther.gameObject);
         TakeDamage(30);
     }
     if (vOther.EType == EntityType.Player)                              //If we hit other player, cause stun
     {
         StartCoroutine(StunPlayers(this, (PlayerShip)vOther, 3f));      //Stub then Unstun after 3 seconds
     }
 }
Example #3
0
 void    SortPlayersByScore(PlayerShip[] tShips)                         //Simple bubble sort, decending order
 {
     if (tShips.Length > 1)
     {
         bool tSwap;
         do                                              //Bubblesort with early exit if sorted
         {
             tSwap = false;
             for (int tI = 0; tI < tShips.Length - 1; tI++)
             {
                 if (tShips[tI].PlayerScore < tShips[tI + 1].PlayerScore)                                //If next score higher than last current one, swap
                 {
                     PlayerShip tTPS = tShips[tI];
                     tShips[tI]     = tShips[tI + 1];
                     tShips[tI + 1] = tTPS;
                     tSwap          = true;                              //Still swapping
                 }
             }
         } while(tSwap);                         //Will fall through is no swaps were needed
     }
 }