public void _PlayerDestroyed()
        {
            if (respawning)
            {
                return;
            }

            //player unit is destroyed, check playerLife and respawn player if need be

            playerLife -= 1;

            if (playerLife <= 0)                //playerLife's used up, game over
            {
                GameControl.GameOver(false);
                return;
            }

            respawning = true;                  //set respawning flag to true to prevent duplicate spawn

            //create a duplicate of current player unit so the selected weapon and ability is retained
            GameObject obj = (GameObject)Instantiate(player.gameObject, player.thisT.position, player.thisT.rotation);

            player = obj.GetComponent <UnitPlayer>();

            //set the new player unit to false to give it a little delay before showing it again
            obj.SetActive(false);

            //call the coroutine which will do the delay and reactivate the new unit
            StartCoroutine(ActivateRepawnPlayer());
        }
 public override void OnTriggerEnter(Collider collider)
 {
     if (collider.gameObject.GetComponent <UnitPlayer>() != null)
     {
         GameControl.GameOver(true);
         Triggered();
     }
 }
Exemple #3
0
        //function call to check all the objective has been completed
        public void CheckObjectiveComplete()
        {
            bool cleared = true;

            //objective status set to true by default, it will be set to false if any of the objective condition is not full-filled
            //cleared flag will then be use when calling GameControl.GameOver, indicate if player win/lose the level

            //if require to wait for timer but time is not up yet, dont proceed
            if (waitForTimer && !GameControl.TimesUp())
            {
                return;
            }

            //if scoring criteria not full filled, set cleared to false
            if (enableScoring && !scored)
            {
                cleared = false;
            }


            if (colPrefabList.Count > 0)
            {
                for (int i = 0; i < colPrefabList.Count; i++)
                {
                    if (colPrefabCountList[i] > colPrefabCollectedCountList[i])
                    {
                        cleared = false;
                        break;
                    }
                }
            }

            //if(clearAllCol){	//if clear all collectible is required and not all collectible is collected, set clear to false
            //	if(GetAllCollectibleCount>0) cleared=false;
            //}
            if (collectibleList.Count > 0)
            {
                cleared = false;                                                //if not all require collectible required has been collectible
            }
            //if either of the prefab kill count is not adequate, set cleared to false
            if (prefabList.Count > 0)
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    if (prefabCountList[i] > prefabKillCountList[i])
                    {
                        cleared = false;
                        break;
                    }
                }
            }

            if (clearAllHostile)                //if clear all hostile is required and not all unit is destroyed, set clear to false
            {
                if (UnitTracker.GetUnitCount() > 0)
                {
                    cleared = false;
                }
            }
            else                //if not all the target unit has been destroyed, set clear to false
            {
                if (unitList.Count > 0)
                {
                    cleared = false;
                }
            }

            if (clearAllSpawner)                //if clear all spawner is required and not all spawner is cleared/destroyed, set clear to false
            {
                if (UnitSpawnerTracker.GetSpawnerCount() > 0)
                {
                    cleared = false;
                }
            }
            else                //if not all the spawner has been cleared/destroyed, set clear to false
            {
                if (spawnerList.Count > 0)
                {
                    cleared = false;
                }
            }

            //if time is up, consider game is complete and call GameOver
            if (GameControl.TimesUp())
            {
                isComplete = true;
                GameControl.GameOver(cleared);
            }
            //else if we dont need to wait for timer and the objective is cleared, call GameOver
            else if (!waitForTimer)
            {
                if (cleared)
                {
                    isComplete = true;
                    GameControl.GameOver(cleared);
                }
            }
        }