- Home /
How do I make a power up?
Hey guys i'm making a 2d game and i want to make a power up where it makes a new 2d character. My script doesn't work.
var OnCollisionEnter();
{
if(OnCollisionEnter is Collider create new 2dCharacter);
}
Answer by superluigi · Sep 07, 2014 at 09:09 PM
Iam Tabu316 if you don't know how to code you need to learn that first. Once it clicks everything gets easier. Here's an easy way though. Make a collider trigger and when your character enters the collider have it become the new powered up character. That's honestly how everybody would probably do it, by using triggers.
function OnTriggerEnter(other : Collider)
{
if(other.tag == "PowerUp")
{
//However you wanna handle it. You can create a new powered up character and destroy the old one, but I personally wouldn't handle it that way. I would just have one copy of each and disable/enable the one that's currently active
}
}
I get what the script is doing but the way I want to handle it is to make a new player
Answer by TimBur · Sep 07, 2014 at 07:13 PM
Your scripting syntax is mixed up in several ways.
First, I think that if you back up a bit, and do a couple tutorials on scripting basics, you'd learn how to avoid some common mistakes, and then be able to do what you want to do faster. At least, that's what I did, and it worked well for me. For example, the Roll-a-ball tutorial (here) shows how to create a pickup, and creating a pickup is the first part of creating a powerup.
Second, when using standard utility functions like OnCollisionEnter, I suggest you begin by copy/pasting the example from the Scripting API help page, and then customizing the code to fit your needs. The example for OnCollisionEnter() is here: http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
Lastly, I think that a powerup might work better if you gave it a trigger-type collider. You can do this by checking the 'Is Trigger' box in the inspector, and using OnTriggerEnter instead of OnCollisionEnter.
when I looked at the video you told me to look at, the script didn't work. Every time I look at a script when I collide with my coin, nothing happens.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162519im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
driving game power ups 1 Answer
Unity 2D - Yoshi styled "PowerUp"-Creature 1 Answer
Upgrades not applying after first death 2 Answers
Coins Multiplier 0 Answers
HELP! With my Speed power up 2 Answers