all done
Ok, here comes a bit list of changes to make, work through them slowly and carefullyâŚ
- Open GameController.cs
- Remove the following two lines of code;
public Text youWinText; public Text youLoseText;
- Add the following line of code;
[SerializeField] private Text outcome;
- Remove the following two lines of code;
private bool youWin = false; private bool youLose = false;
- Within the
Start
method, remove these two lines of code;youWinText.text = ""; youLoseText.text = "";
- Add the following line of code;
outcome.text = "";
- Within the
OnGUI
method (questionable usage, this should be replaced later)- Change this line of code;
to;youWinText.text = "You Win!";
outcome.text = "You Win!";
- Remove this line of code;
youWin = true;
- Change this line of code;
to;youLoseText.text = "You Lose!";
outcome.text = "You Lose!";
- Remove this line of code;
youLose = true;
- Change this line of code;
- Save the script
- Within Unity, select the GameController within the Hierarchy
- Drag the Outcome UI Text GameObject to the Outcome field, exposed in the Inspector
- Run the game, you wonât see much difference but there should be no errors in the console
okay will work on this
Iâll hang around for another 15 minutes.
Nice!! it works!! but after I kill 12 enemies the You Lose! message appears then I kill the last enemy and the You Win! appears it this accurate?
Youâre rushing ahead.
Very Awesome
I Thank you sorry for rushing
So, looking at the conditions we want to serve;
Letâs tackle the top one first.
Looking at the ways which you are detecting collision you have a CollisionHandler.cs script and you also have a DestroyByContact.cs script. Both make calls to the GameOver
method within GameController.cs.
When I use Find all references for the DestroyByContact.cs script within Unity I donât find anything that is using it.
Can you confirm this is the case and state any reason why we shouldnât delete it.
I will delete it.
Ok, so DestroyByContact.cs is now gone.
If you know look at the GameOver
method within GameController.cs, within Visual Studio, right-click on it and select âFind All Referencesâ you should only see the one reference which is for the CollisionHandler.cs script.
Correct?
- Scroll down to the method name
GameOver
. - Right-click on it (on itâs name)
- Select âFind All Referencesâ
Okay
Good.
So we know that currently the only code that is calling the GameOver
method is the CollisionHandler.cs script.
Now, back into Unity, select the CollisionHandler.cs script, right-click and select âFind References In Sceneâ.
You should see a filter Hierarchy on the left with two entries, the Game Controller and the Player Ship.
Correct?
Let me check.
Got it.![Screenshot%20(28)|690x388]