# Algorithm examples of how pickups are handled

## Recommended Posts

Hmmmm this is closer I think but it's not always the Paddle it will collide with, sometimes it might be the ball. If I made the PowerUpManager static and put it on the ball and the paddle, would that male it so it would all track in one place no matter which object the pick up hits?

##### Share on other sites
1 minute ago, ethancodes said:

Hmmmm this is closer I think but it's not always the Paddle it will collide with

Then just add two collisions or do an or check.

if(col.gameObject.name == "Player1" || col.gameObject.name == "Ball")

Other possibilities is to give the ball and the player the same tag. Moving them to the same layer also allows for layer checks. You could even add a variable to the objects and check for it on collision.

There really isn't a way around this; you will always make more code the more you need to do.

With that said, learning the observer pattern is a good thing if you want to try it just to learn. You will use it a lot in complexer games. It's just that most of the code Unity uses already follows this pattern.

##### Share on other sites
Posted (edited)

I really want to learn the observer pattern, however I think I found a solution that is going to really cut out a lot of code, so I'm going to go with that.

Edited by ethancodes

## Create an account

Register a new account

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633293
• Total Posts
3011236
• ### Who's Online (See full list)

There are no registered users currently online

×