x


PickUp Weapon in Brick Breaker Game

Hi i created brick brekaer game and weapon it work great. But i dont want to player have always a weapon, i want to create a script so when player destroy every 20 brick, from top will be spawned pickup weapon object. I'm not asking you to make me all of that , just to help me to crate script that will Instantiate weapon object and stick it to player when player pickup weapon object! Tnx in advance!

more ▼

asked Aug 04 '11 at 06:07 PM

slajmstudio gravatar image

slajmstudio
1 5 5 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

okay, a solution that can be translated into working code. First, counting bricks. You need to have a variable to store how many bricks hit so far. Secondly, you need to check if you have reached that limit.

Lets call it:

int brickHits = 0; // default is 0

Every hit will +1 to this variable.

so you need a function like:

void BrickHit()
{
   brickHits++; // ++ is short for +1 

}

After adding +1 then check if brickHits is above your wanted limit (20)

void BrickHit()
{
   brickHits++; // ++ is short for +1 
   if(brickHits>20)
   { 

       // okay above 20, lets do something, 
       // also remember to re-init the variable for the next weapon drop.

       // here you could spawn your weapon drop, play a sound or whatever.
   }


}
more ▼

answered Aug 05 '11 at 01:21 AM

BerggreenDK gravatar image

BerggreenDK
2.4k 54 62 75

tnx you gave me idea ;)

Aug 05 '11 at 12:57 PM slajmstudio

ok i made it it works , but when player destroy 20 bricks, it spawn new collection on every next destroyed brick, it looks like rain of collection objects :D

Aug 05 '11 at 01:24 PM slajmstudio
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x220
x141

asked: Aug 04 '11 at 06:07 PM

Seen: 826 times

Last Updated: Aug 05 '11 at 01:24 PM