Can you give provide feedback/insight on the gameplay of my game Portal Reign?

Okay.

Ready for some more?

I still receive the message Enemies remaining :1 throughout the whole game play even after applying your instructions.

Isn’t that because there is an enemy in front of you in that scene?

if I shoot the enemy it still states remaining:1

Chances are you still have a GameObject in the scene with the enemies tag that doesn’t need it then.

That is what I thinking to I looking for it. Hold on

When I checked at this end, you had tagged the GameController and the Enemies GameObjects - both need to be set to Untagged

I found the issue but the game says all gone all the time it was I had the Enemies tag on the the parent
Enemies

Yeah, that’s what I said above. :slight_smile:

Ok - so all sorted again now?

Did you want it to say all gone all the time?

It should only be saying that when the last enemy is destroyed.

I will try again.

Just to check, in that screenshot above, is that at the beginning of the game, or, have you circled all the way around and effectively started again?

Also, when I said “Enemies” above, I was referring the GameObject called “Enemies”, I didn’t mean changing the tag of the actual, individual, enemies - those should still be set to “Enemies” - if that makes any sense.

The begining

Yes this is what I did.

So it should be like this (excuse awful diagram), I’m rushing here a bit…

image

Okay got it. Hold on.

Same results

Great, ok, lets do the next bit…

Performance tweak…

This is bad -

void Update()
{
    GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemies");
    enemiesLeft = enemies.Length;

    if (enemiesLeft == 0)
    {
        endGame();
    }
}

Currently, every single frame you search the entire scene and try to find GameObjects that are tagged “Enemies”. All of the “Find” methods are slow and should be used sparingly, certainly not in an Update statement. Another problematic issue with this approach is, and you may have already spotted it, but when the game runs, your count gradually increases as you fly around the scene. The reason for this is because at the start of the game the Timeline is disabling all of the GameObjects that are not required at that time. You count is running each frame and just returns a count of what is “active” at that time in the scene, not all of the enemies that the player needs to shoot in the level.

If you add this one line to your Start method within GameController.cs;

Debug.Log("Enemy Count : " + GameObject.FindObjectsOfType<Enemy>().Length);

At the beginning of the game you’ll get the total of all enemies that are in the scene. Whilst it is still using a “Find” method, it is now only occurring once, so hugely better from a performance perspective. The issue about only returning the number of “active” GameObjects is still true, however now you are capturing the count before Timeline disables any GameObjects. Now, this could be by chance, as the Timeline’s Playerable Director is set to “Play on Awake”, we could move this line into an Awake method but again, the Timeline could be run first, to be certain we would need to consider changing the script execution order to ensure that this count is obtained before the Timeline disables anything.

For now I’d not worry about that, if you get the result you need, then maybe just make a note in a comment about the script execution order in case its something which bites you later.

Now, as we can output the count using the Debug.Log statement, we can also just set the variable here, once, so;

void Start()
{
    enemiesLeft = GameObject.FindObjectsOfType<Enemy>().Length; 
    restartText.text = "";
    gameOverText.text = "";
    youWinText.text = "";
    youLoseText.text = "";
    score = 0;
    UpdateScore();
    StartCoroutine(SpawnWaves());
}

and then you can update the Update method to no longer perform this “Find”;

void Update()
{
    if (enemiesLeft == 0)
    {
        endGame();
    }
}

Run the game, and you’ll find that it states 13 enemies at the top left, and, as you shoot them it won’t currently decrease, this is ok, get to this point and then let me know :slight_smile:

Privacy & Terms