My Block Breaker!

Hi,
here is my block breaker game, I have altered it a bit but not much.
I would like to add lives, but so far I’ve come up blank, so if anyone could help me there it would be greatly appreciated.

Block Off

1 Like

I noticed the metal clang you used for the metal parts of the 1st level. I’ll give you guidance on how I added lives to my project. Although I had trouble making the lives static so I had to make number of lives unique to each level. Hope that’s enough?

I had LoseColliderScript.cs talk to PaddleScript.cs: LoseColliderScript.cs detects when the only collider that will be touching it (the Ball) and subtracts 1 life from PaddleScript.cs. Once the ball touched the Lose Collider in runtime, I set the “hasStarted” bool in BallScript back to false to lock it back to the paddle’s transform. Finally, when the lives reach 0, I had LevelManager.cs load the Lose Screen.

Before I begin listing the steps, I’m letting you know I named my scripts different from Ben: the same as his but ending it with “-Script”. I also used the old school GUI Text to display the lives instead of the newer UI system.

In PaddleScript.cs
1.) Declare “public int lives” and set it to any integer you want.
2.) Declare “public GUIText livesText”
3.) In Start, write "livesTxt.text = “Lives: " + lives.ToString();”

In LoseColliderScript.cs
4.) Declare “private PaddleScript paddleScript”
5.) In Start, write “paddleScript = GameObject.FindObjectOfType(PaddleScript)();”
it won’t let me use carrots in step 5 around “PaddleScript”. Pretend there are carrots surronding it.
6.) In OnTriggerEnter2D, write “paddleScript.lives–;” and “UpdateLivesTxt”
7.) In OnTriggerEnter2D, Write:

if (paddleScript.lives <= 0)
{
Lose();
return;
}

8.) right below that if statement, write: “ballScript.hasStarted = false;”
9.) Declare “public void Lose” function. In it, write: “levelManager.LoadLevel(“Lose Screen”);”
10.) Declare “public void UpdateLivesTxt” function. In it write:
"paddleScript.livesTxt.text = “Lives: " + paddleScript.lives.ToString();”

I hope I listed all that right without screwing anything up. Of course, don’t forget to hook up a GUIText gameobject to the public variable on the Paddle gameobject. Try it out and get back with me. :slight_smile:

Below I included my scripts so you can go over the way I did it.

Helper Scripts.zip (1.8 KB)

1 Like

Cheers mate, thanks for your help, I’ll hopefully have a go at it at the weekend. :smiley:

Hello, Lee. Did you get any work done on adding lives?

Not had a chance yet mate, I forgot I was on call this weekend and as it is a bank holiday weekend I’ve been too busy with work, did a 14 hour day yesterday and I doubt today and tomorrow will be any better. Might have to wait until next weekend. :frowning:

I have managed to clear up a few bugs and tart it up a bit today. :slight_smile:

Block Off

Privacy & Terms