- Home /
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!
Answer by BerggreenDK · Aug 05, 2011 at 01:21 AM
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.
}
}
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
Your answer
Follow this Question
Related Questions
weapon pickup 1 Answer
How do I fix my gun animation 0 Answers
How can I detect if box is touching a tag named weapon? 1 Answer
ramdomised weapon pickup 1 Answer
Weapon pick up 3 Answers