Trying to make a "grow" powerup in breakout style game.

I’ve never created much of anything before, so this is my first time scripting (with C#.) I tried to make a simple script with different things I could find online. This is what I came up with

 void OnCollisionEnter2D(Collision2D powerUpCol)
    {
        if (powerUpCol.gameObject.name == "Player")
        {
            var grow = GameObject.FindGameObjectWithTag("Player");
            Vector2 originalScale = grow.transform.localScale;

            grow.transform.localScale = new Vector2(1.25f, 2.9f);

        }

This is the script attached to the powerup itself. It obviously doesn’t work, and I’m wondering if anybody has any better ideas on how to make this type of powerup.

Thanks for any help!

PS: Again, I’m very new to coding, so I’m sorry if this is a stupid question…

This is not obvious. We’re not mind readers.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

The problem is that you are growing the powerup, instead of the player.
It should be something like this:

void OnCollisionEnter2D(Collision2D powerUpCol)
    {
        if (powerUpCol.CompareTag("Player"))
        {
            powerUpCol.transform.localScale = new Vector2(1.25f, 2.9f);
        }
}

This way, the powerup will compare the collision with it’s tag “Player”, then apply the scale to the one you set previously.