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

Okay

Have the same result as described above?

Yes all done it doesnā€™t count down though like you stated :slight_smile:

Great, thatā€™s what we wantā€¦ ok, next bitā€¦

Before we start, delete the KillEnemy.cs script, it isnā€™t being referenced by anything and we have a few similarly named things in this project, it will be good to cut one loose :slight_smile:

In order to reduce the count, we want the enemies to report ā€œIā€™m deadā€ to the GameController. Initially we can just use a method call to do this, but later on you could consider using events/delegates - letā€™s keep it simple for the time being.

Soā€¦ letā€™s add a simple method to GameController.cs to help reduce the number of enemies;

public void DecreaseEnemyCount()
{
    enemiesLeft--;
}

That gives us something to call, but we need to call it from something. As the enemy is being destroyed, it makes sense for the enemy to communicate back to the GameController.

You already have a method named KillEnemy within the Enemy.cs script and this class already has a member variable storing a reference to the GameController, perfect, letā€™s add a line of code to the existing method;

private void KillEnemy()
{
	GameObject fx = Instantiate(deathFX, transform.position, Quaternion.identity);
	fx.transform.parent = parent;

	gameController.DecreaseEnemyCount();
	
	Destroy(gameObject);
}

Run the game, you should now find that as you shoot the enemies, the count at the top reduces.

Yes it counts down but its not accurate the count misses two enemies and states all gone before the enemies have all died.

It is miss counting the last five ships and stating all gone to soon.

Thereā€™s a reason for that, and I was just writing it up for you. :slight_smile:

Bug fix

I have discovered whilst testing with the one enemy, that if I shoot it, I can get a remaining enemy count of -1, that would indicate that that our KillEnemy method is being called more than once, and in doing so, it calls our GameControllerā€™s DecreaseEnemyCount method more than once for each enemy.

The problem here is the logic being used within the OnParticleCollision method of Enemy.cs.

It only cares if the value is less than or equal to one, so if two particles hit in the same frame this message is sent twice and the code will run twice. We need to put a little fix in for that.

We could use a bool, perhaps an isDead flag, and then set it, and test that in this logic, but we already have that. We have itā€™s enabled/disabled state, so letā€™s use what we already have;

Update the OnParticleCollision method as follows;

void OnParticleCollision(GameObject other)
{
    ProcessHit();
    if (hits <= 1 && gameObject.activeSelf)
    {
        KillEnemy();
    }
}

and then within the KillEnemy method will set the GameObject to be disabled;

private void KillEnemy()
{
	GameObject fx = Instantiate(deathFX, transform.position, Quaternion.identity);
	fx.transform.parent = parent;

	gameObject.SetActive(false);

	gameController.DecreaseEnemyCount();

	Destroy(gameObject);
}

So, when the first time the KillEnemy method is called, it will disable the GameObject, the second time a particle makes the collision and the hits are less than or equal to one, the GameObject will no longer be active so the second part of the condition will fail and KillEnemy will not be called a second time. At the end of the frame the GameObject is actually destroyed.

Ok, so thatā€™s five hours of my time and about 40 posts between us. It is now official time for me to get some food :slight_smile:

Thank you so much :slight_smile:

Ok, the food is cooking.

So, what is left that needs to be done, from your perspective, not for the entire game, but just for these issues you were having?

You have so far;

  • the count of all enemies in the scene
  • the count reduces when they are destroyed by the player
  • game over is triggered when the player crashes

Its okay we can finish up another time enjoy super. I will reach out to you next week I would like to try and tackle some on my own and get back to you where I get stuck. I Thank you for all you do, Hope itā€™s Okay :slight_smile:

No problem at all, go for it :slight_smile:

Hi Rob Good Morning, I get the game to to sates the You Win! message after killing all the enemies, But I canā€™t get the game to to state at the end of the main timeline if enemiesleft to state the You Lose! message. it states both message when I killAllEnemies
if I remove the youLose statement the youWin statement still works. Thank you

 void endGame()
    {
        killedAllEnemies = true;
    }

    void OnGUI()
    {
        if (killedAllEnemies)
        {
            youWinText.text = "You Win!";
            youWin = true;
        }
        else if (enemiesLeft <= 1)
        {
           youLoseText.text = "You Lose!";
            youLose = true;
        }


These are the errors I receive :confused:

Should have kept going last night Martin, I had time available then. Unfortunately I wonā€™t be available until next week now. Happy to pick back up in due course. :slight_smile:

No Worries Pal, just when you have time get back to me Thanks :slight_smile:

Out of interest, how familiar with Git/GitHub are you?

Iā€™m conscious each time I help I need to download your most recent version because youā€™ll have made changes in between which involves download a whole load of things that havenā€™t changed and wastes time. If you are familiar with Hut and GitHub you could commit it all to a repo and then Iā€™d only need to get the changes each time.

Just a thoughtā€¦

I read into it over the weekend get back to you soon :slight_smile:

Ok. It can be a bit bewildering at first. I would highly recommend using a GUI client instead of the command line, GitKraken is very good and is free.

I would also highly recommend practicing with a test/dummy project, not something you would be concerned if you lost. Just as a precaution. :slight_smile:

Okay I just trying to get a hold of contacts at my school to discuss March session. I will work on this a little later.

1 Like

Hi Rob, I Thank you GitKraken seems a lot more fun and easier to use. I wish Ben had use this from the start. I committed my files when your ready to look over it let me know how to share with you. :slight_smile:

Privacy & Terms