• 9
• 10
• 10
• 9
• 10
• ### Similar Content

• I'm having a weird issue with detecting a collision. I've tried everything I could find online but nothing seems to work. I have a brick object. It has a 2D Collider attached and I have also attached a 2D Rigidbody on it. I also have an EndScreen 2D Collider. The EndScreen 2D collider is tagged with "EndScreen". I am trying to detect when a brick collides with the end screen collider and simply print "game over" in the console.
This is my current code for this part of the program, it is attached to the bricks:
void OnCollisionEnter (Collision2D collision) { if (collision.gameObject.tag == "EndScreen") { Debug.Log("Game over"); } } Several things have happened depending on the set up. If I have the rigidbody 2D set as static, my ball object can still collide with the bricks, but I get no Log message. If I set it to Kinematic or Dynamic, I get absolutely no interaction between the ball and the bricks, and nothing when the bricks pass through the collider. I have tried to set the collider to a trigger and use OnTriggerEnter2D, no change. I have tried to put the rigidbody on the EndScreen object and tried to set it's body type to all 3 settings, no change. The only thing I can think of that I have not done is put the script on the EndScreen object and switch the tag to the bricks. The reason I have not done this is because I will have several types of bricks, some of which will have different tags.

Please tell me somebody can see what I'm doing wrong here, because I'm losing my mind over something I feel should be ridiculously simple. Thanks.

# Unity Programming patterns my reward system

This topic is 526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have this reward logic in my reward ,  my goal is to build a library which I can keep reuse later , however by this following method I can't

class RewardSystem
{

float m_timer;
void Update()
{
m_timer -= time.deltaTime;
}

void btn_Reward()
{
if(m_timer > 0)
{
{
CoinSystem.m_coins += 100;
}
}
else
{
CoinSystem.m_coins += 100;
}
}
}


The problem I'm having here is if the user does not have want to have ads system instead doing something else to collect coins or they decided to collect the coins with just pressing a button without looking the ads, people would need to rewrite it, and also it breaks the SOILD principle. So I'm wondering is there any programming patterns can help me to solve this problrem ,thanks

##### Share on other sites

but adding complexity for the sake of possible future scenarios is over-engineering.

this

##### Share on other sites

If you need to seperate this logic then create another class- and think of abstractions.

"I have an abstracted logic for doing an activity, in the end it returns the state of the activity and rewards the player."

So:

interface IActivity {

bool Run();

}

class A {

IActivty MyActivity;

void Reward() {

var result = mMyActivity.Run();

if(result) { coins +=100;}

}

}

Edited by WoopsASword