• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by waittobi · Dec 16, 2016 at 06:58 PM · c#scripting beginner

Creating Super Power

I'm just hoping someone can steer me in the right direction . What I'm trying to do is have special pick up that once my player enters the trigger he gain special powers for a limited time ... for example red will give him super speed and double jump, green munipulates his size so he can go into narrow areas , blue makes him able to stick to walls .. yellow would b immortality like superMario star power ... so on and so forth.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheUltimateKerbonaut · Dec 16, 2016 at 07:42 PM 0
Share

Hi waittobi. Are you asking how to make certain pick-ups pick-uppable and/or just code the powerups so they do something?

avatar image waittobi TheUltimateKerbonaut · Dec 16, 2016 at 07:47 PM 0
Share

i already have the pick up script that changes my player color and it already has the limited time feature .... what i want is some sample code or something that i can put onto the pickup object to give him the powers each power is different so I'm not sure how to go by it .... i hope I'm wording this right so I'm as understandable as possible
@theUltimate$$anonymous$$erbonaut

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TheUltimateKerbonaut · Dec 17, 2016 at 08:24 AM

For implementing the power-ups, I would probably use the player controller script. For the super speed and double jump, maybe try something like this:

 public float speed; //You probably already have this in your script in some form or another, so feel free to discard this line if need be.
 public int jumpsAllowedOffGround;
 public float speedPowerupMultiplier;
 
 public void onRedActivated() {
     jumpsAllowedOffGround = 2;
     speed = speed * speedPowerupMultiplier;
 }
 
 public void onRedDeactivated() {
     jumpsAllowedOffGround = 1;
     speed = speed * speedPowerupMultiplier;
 }

For changing the size, this might be helpful:

 public float smallerScaleX; //This is the scale of the character, just like you would use in the editor
 public float smallerScaleY;
 public float smallerScaleZ;

 public float normalScaleX;
 public float normalScaleY;
 public float normalScaleZ;

 public void onGreenActivated() {
     transform.localScale = new Vector3 (smallerScaleX, smallerScaleY, smallerScaleZ); // This scales it like you would expect. It requires a Vector3 as it needs x, y and z;
 }

 public void onGreenDeactivated() {
     transform.localScale = new Vector3 (normalScaleX, normalScaleY, normalScaleZ);
 }

For wall climbing it would be best to see a dedicated post on the Unity Answers (try here), and for immortality, you would just need to pass some sort of boolean declaring if a player can die or not when hitting and enemy or something:

 public bool immortal;

 public void onYellowActivated() {
     immortal = true;
 }

 public void onYellowDeactivated() {
     immortal = false;
 }

 public void onPlayerShouldDie() {
     if (immortal == false) {
         //kill the player or something
     }
 }

Remember that the variables in all the above code are public, and therefore can be assigned in the editor (make sure you don't leave them at 0). All the best and good luck with your game :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image waittobi · Dec 17, 2016 at 09:45 PM 0
Share

OH man thanks so much this is extremely helpful..1 last question how do i assign the function to the object.. like how does it know to activate the function once its passes thru the trigger ... sorry if this is a newbie question @TheUltimate$$anonymous$$erbonaut or maybe i should put the public functions in the object script

avatar image waittobi waittobi · Dec 18, 2016 at 03:01 AM 0
Share

nvm go it !!...thanks again you've been a real big help I really appreciate it

avatar image
0

Answer by Havax · Dec 17, 2016 at 08:01 AM

If you've created a player that is already controllable, then you must've set certain values on it, such as speed, and jump height. If you already have the script that allows the player to collect the 'powerup' for a certain amount of time, allow that power up to access the Player's script, and modify the speed values, to where they will be reverted when time runs out. Things like double jump will be slightly more complicated, since you will have to code in the feature first, and then can unlock it through a boolean value when the powerup is collected. It took me a while to recode Unity's FPC to double jump when I first began, but it should be relatively simpler for 2D. To change his size, just modify his transform. If the player has a health value, you can disable this to make him immortal.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

284 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you make your player jump in the Roll-a-Ball tutorial series? 0 Answers

How do I inactivate Text in a script? 2 Answers

How would I use other.gameobject like I've seen in collider scripts? to work in my camera script 0 Answers

I made this but why do i only jump one time 1 Answer

HELP! How to make Update function start after delay? C# 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges