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

If you have destroyed the enemy then it isn’t going to be returned in the count of active GameObject with the tag.

I suspect the reason you are not seeing the enemy GameObjects being destroyed is because your if statement is never true.

To test the theory, where you have the check to see if you return more than 13 active enemy GameObjects, above that, outside of theif statement, just output using Debug.Log how many there are with the tag.

Hi Rob, sorry for the lengthily post. So then I should determine how many enemies are left to end the game then show the (You win Game Over!!) message correct? Or I’m going about all the wrong way? I thought I need to count and tag all the enemies with enemies tag so I can end of game with the (You Win Game Over!) message. If the player does not shoot all the enemies at the end of the timeline (player rig) then a message should say (You lose try again!) I haven’t worked on the (You lose try again!) message because I don’t have the the count working to see how many enemies are left to end the game with the (You win Game Over!!) So this is want I want to do before I upgrade the ships in the asset store and by other items to make the game look and feel even better besides work on how the player movement to make it smooth out in the turns. My goal is to make it complete mine and sell it for PC and handle Devices this game I will introduce my game (Latmian of Ra) read more about the game at my websites https://www.dmmsdi.com. I going to the messages idea during the game like Rick showed use with( admiral fish head) to point out caves I will add to the terrain that the player will see during is attack and defense. At the end make another splash screen with the player landing and coming out of the ship to to investigate. I hoping you can guide me or send me to the correct Unity forums that can help me complete Portal Reign the way I want to. So I can start creating (Latmian of Ra) its a first person shooter game. I Thank you for all your guidance BTW. Merry Christmas Pal :santa:

So, did you try the Debug.Log statement like I suggested so you could output how many tagged enemies there were in the scene before you run the if statement?

Merry Christmas to you also Martin, and thank you :slight_smile: :santa:

Hi Rob, Thanks for staying in touch, I’m still stuck on where this: code belongs in the enemy.cs or in the killEnemy.cs I created.
I can’t get the count to happen in debug because I don’t no where to make the if statement (true). Should I create new text objects on the canvas for (You Win!) and (You Lose!) messages

In the GameController.cs Should I add this for the You Win & You Lose messages to work like this:

void Start()
{
youWin = false;
youLose = false;
gameOver = false;
restart = false;
youWinText.text = “”;
youLoseText.text = “”;
restartText.text = “”;
gameOverText.text = “”;
score = 0;
UpdateScore();
StartCoroutine(SpawnWaves());
}

public void YouWin()
{
youWinText.text = " You Win Game Over!";
youWin = true;

    masterTimelinePlayableDirector.Stop();
    enemies.SetActive(false);
}

public void YouLose()
{
youLoseText.text = " You Win Game Over!";
youLose = true;

    masterTimelinePlayableDirector.Stop();
    enemies.SetActive(false);
}

}
Should the if statement you discuss look like this? Which .cs does it belong to Enemy.cs or kilEnemy.cs? and do iI attach it to a object in the inspector like the player ship or the enemies?

if (GameObject.FindGameObjectsWithTag(“Enemies”).Length > 14)
{
Destroy(gameObject);

public void YouWin()
{
youWinText.text = " You Win Game Over!";
youWin = true;

    masterTimelinePlayableDirector.Stop();
    enemies.SetActive(false);
}

public void YouLose()
{
youLoseText.text = " You Win Game Over!";
youLose = true;

    masterTimelinePlayableDirector.Stop();
    enemies.SetActive(false);
    }
``}
}
        
:santa:

This is where I’m so far the game doesn’t produce the game over message nor the Press ‘R’ for restart.

Hi Martin,

This is a bit too lengthy to go through today, family etc, but the reason I asked you to put the Debug.Log statement in your code above where you already had the if statement was to diagnose the issue.

At the moment your code is saying “are there more than 13 enemies, ok, great, destroy one”, but at some point that is going to fail, e.g. When you have destroyed enough and there is only 13 left, then that if statement won’t return true and your Destroy method will not be called. The enemy ship will be left in place.

This is the behaviour you described you had at the beginning and I was trying to get you to do a bit of a diagnosis so that you would see, perhaps, that you never have more than 13 enemies, or maybe at some point you only have 13 enemies, in both cases the Destroy method won’t be called.

I believe you have a GameController GameObject and class, this would be the ideal object to be monitoring the count of enemies in the game. At the start of the game it should run off and return the count of the enemies that are perhaps tagged, or, you could find them by type if they have a class on them. The Game Controller now has a variable storing the total number of enemies in the scene.

When one of your enemies gets destroyed you then need to reduce that count by one. At the point of reducing this count you should also check to see if there are any left. If the count of all enemies in the scene is now zero then trigger the game iver condition, for now that could just be a Debug.Log statement if you are still having problems with the UI.

As part of this, you could also consider the ability to increase the number of enemies that are in the scene. Perhaps instead of searching the scene for all of the enemies that are tagged, if you have an enemy script on each enemy, in its Awake method it could communicate with the Game Controller and call a method that increases the number of enemies by one. Each enemy would then notify the GameController at the start of the game.

On a side note, if you could apply the code formatting characters when copy/pasting your code into the forum too that would be helpful as it makes it easier to read.


See also,

I apologize, I forgot this is good family time, I’m having many issues with my own so I stay home like always never the less is a bless day, I talk to who I can in my family and who doesn’t insult me for not having a job yet. I hope to chat with you after the New Year and get this game completed :slight_smile: Thank you

No need to apologise Martin, I am dipping in from time to time via my mobile which is why its a bit harder to do the lengthier, more in depth, responses.

I have my son 50% of the time, his mother the other 50%, I fully appreciate the emotional side of this time of year.

Not being employed can be tough, I am currently not employed myself and have also noted how people’s attitudes towards you can change, in my own experience this had affected my confidence and belief that I could still do what I did before.

We all have to travel our own journeys, following a path, but sometimes cut a new one when the existing one does appear to take us where we want to be.

I hope 2019 will be good to you and wish you every success.

Yes it’s hard at times, what makes it harder is the fact the news states unemployment rate is so low I beg to differ at this point. I have sales experience not one company I applied to has called me. I just finished school find it harder to get a job with skills I already have not necessarily in multi media graphic design. I been out of work 1yr and half thus far I always had some type of work painting / maintenance its’s not easy to find at this time.

I’m sure you going to land something with the skills you have. Its not easy being unemployed with a family to support. I starting to get a picture whats happening across the glob .You and your family are in my prayers. It’s lovely to have kids around my sister and cousins kids are pleasant to be around and watch them grow. I’m understanding how hard it is to get good work in this business. I hope my school can help me land something soon applying on my own is not working out for me. I believe companies just can’t not afford skilled employees it may be inexpensive to hire someone with lesser skills for part-time status. I hope the new year brings you and your family good fortune. Thank you

This is what I got done so far but still can get Game Over! or press ® for restart to show or work the You Win! message and You Lose! message don’t show either but they are all hidden when I play the game. Just let me know if I’m on the right track? In debug it actually count enemies. Thank you

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.UI;
using System.Collections;

public class GameController : MonoBehaviour
{
    
    public GameObject hazard;
    public Vector3 spawnValues;
    public int hazardCount;
    public float spawnWait;
    public float startWait;
    public float waveWait;

    public Text scoreText;
    public Text restartText;
    public Text gameOverText;
    public Text youWinText;
    public Text youLoseText;
    [SerializeField]private PlayableDirector masterTimelinePlayableDirector;
    [SerializeField]private GameObject playerShip;

    private bool gameOver = false;
    private bool restart = false;
    private bool youWin = false;
    private bool youLose = false;
    private bool killedAllEnemies = false;
    private int score;
    private int enemiesLeft = 0;

    void Start()
    {
        enemiesLeft = 13; 
        restartText.text = "";
        gameOverText.text = "";
        youWinText.text = "";
        youLoseText.text = "";
        score = 0;
        UpdateScore();
        StartCoroutine(SpawnWaves());
    }

    void Update()
    {
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemies");
        enemiesLeft = enemies.Length;
        if (Input.GetKeyDown(KeyCode.A))
        {
            enemiesLeft--;
        }
        if (enemiesLeft == 0)
        {
            endGame();
        }
    }

    void endGame()
    {
        killedAllEnemies = true;
    }

    void OnGUI()
    {
        if (killedAllEnemies)
        {
            GUI.Label(new Rect(0, 0, 200, 20), "all gone");
        }
        else
        {
            GUI.Label(new Rect(0, 0, 200, 20), "Enemies Remaining : " + enemiesLeft);
        }

        if (restart)
        {
            if (Input.GetKeyDown(KeyCode.R))
           
            {
                Invoke("LoadFirstScene", 2f);
            }
        }
    }

    IEnumerator SpawnWaves()
    {
        yield return new WaitForSeconds(startWait);
        while (true)
        {
            for (int i = 0; i < hazardCount; i++)
            {
                Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnWait);
            }
            yield return new WaitForSeconds(waveWait);

            if (gameOver)
            {
                restartText.text = "Press 'R' for Restart";
                restart = true;
                break;
            }
        }
    }
     
    public void AddScore(int newScoreValue)
    {
        score += newScoreValue;
        UpdateScore();
    }

    void UpdateScore()
    {
        scoreText.text = "Score: " + score;
    }

    public void YouWin()
    { 
        youWinText.text = "You Win!";
        youWin = true;
    }

     public void YouLose()
    {
        youLoseText.text = "You Lose!";
        youLose = true;
    }

    public void GameOver()
    {
        gameOverText.text = "Game Over!";
        gameOver = true;

        masterTimelinePlayableDirector.Stop();
        playerShip.SetActive(false);
    }
}


These are the errors I receive:

HI Martin,

I’ve got a little bit of time on my hands today, so if you would like to share your project files again, as they are at this time, but without the library directory I will be happy to take another quick look.

Lets try to resolve some specifics though, so, from my current understanding, you want;

  • to be able to count the number of enemies in the scene
  • to be able to reduce the number of counted enemies as they are destroyed by the player
  • to display the Game Over UI objects when;
    • the enemy count reduces zero
    • the player is killed

Anything other than that at this time?

Hi Rob, Thank you I zipping will post when it’s done. I hope your holiday spent with your wife and child was pleasant ? :slight_smile:

Thank you Rob,

https://drive.google.com/file/d/1ZXD3n-ebzdhu1jgT0dvO7cHexGi2Fd4w/view?usp=sharing

Downloading now, will take a look and respond in due course.


Updated Thu Dec 27 2018 16:55

Just to let you know, we appear to be experiencing some broadband issues and the speeds I am getting are fairly awful. Your file is downloading, but painfully slowly. If you don’t see a response for a while it’s not because I’ve forgotten, it’s because I’ve not got the file! :slight_smile:

oOhh, No worries pal I hope your speed gets up and running again. I think when I removed the library it didn’t save the you lose and you win message I created. I thank for all you do. :slight_smile:

Resolved the networking issues now, have the file, will be taking a look in a sec.

The /library directory is, for all intents and purposes, a copy of your project, so if you had the files/changes in your project they should still be there, e.g. not related to the /library folder.

Okay keep me posted.

Will do.

Thank you

In that long post I did above which had all the steps required to get where I had got to, I had missed something.

I was just looking at your CollisionHandler.cs script and note that you’ve added this;

private GameController gameController;

private void Start()
{
    gameController = FindObjectOfType<GameController>();
}

…but nothing else in that script uses it.

Looking at my instructions above, I indicated to make these changes and then moved to the GameController.cs script where we create the GameOver method - the CollisionHandler.cs script was then meant to call that method but it would seem I forgot to add that instruction for you - my apologies.

So, in your CollisionHandler.cs_ script, make this change;

void OnTriggerEnter(Collider other)
{
    StartDeathSequence();
    deathFX.SetActive(true);

    gameController.GameOver();
}

You can now see the call to the GameOver method.

Make this one change and you should find that when you crash into an enemy the player ship disappears, the movement along the rail stops, and the “Game Over!” text appears.

Do this before we move on as that will save creating a huge post with multiple instructions.


Also, this code;

void Update()
{
    GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemies");
    enemiesLeft = enemies.Length;
    if (Input.GetKeyDown(KeyCode.A))
    {
        enemiesLeft--;
    }
    if (enemiesLeft == 0)
    {
        endGame();
    }
}

in your GameController.cs isn’t going to do what you want it to. Update is called every frame, but above your keyboard input check you are getting a fresh count of how many enemies you have left, so whilst you deduct one when your press A, the next frame it gets a fresh count to corrects it again.

I’m guessing you are using a GamePad when you play, as an aside, you have the KeyCode.A for this check which is also the same key to move the ship to the left :slight_smile:

I would just delete this for now;

if (Input.GetKeyDown(KeyCode.A))
{
    enemiesLeft--;
}

Let me know when you’re ready and we’ll move on to the next bit.

Privacy & Terms