Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Arachnos · Jun 19, 2011 at 11:19 AM · javascriptif-statementsif-else

Power-Ups scripting error

Hey,

I'm currently working on a space shooter and I'm starting to add power-ups to it. I had a power-up that gave you an extra life but then i switched from lives to health and I'm having a bit of trouble. I'm sort of familiar with If statements but not sure how to format them using Javascript. I want to be able to add 50 health if the players health is below 50 points, and if their health is at 50 or above i want to just make their health an even 100.

Here's what I have:

(Scripts Below)

I also tried doing a If/Else statement but I also wasn't sure how to do that. Any help is appreciated and if I'm doing it completely wrong then just say so! :P

Thanks.

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 Arachnos · Jun 19, 2011 at 11:20 AM 0
Share

$$anonymous$$y script got cut off up there so here's what I have.

avatar image Arachnos · Jun 19, 2011 at 11:21 AM 0
Share

function OnTriggerEnter(otherObject: Collider){

 if(otherObject.gameObject.tag == "bonus1" && playerLives <= 50){
 
     playerLives += 50;
     
     Destroy(otherObject.gameObject);
     
 }

 if(otherObject.gameObject.tag == "bonus1" && playerLives >= 50){
 
     playerLives == 100;
     
     Destroy(otherObject.gameObject);
     
 }

1 Reply

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

Answer by PurpleHeartGames · Jun 19, 2011 at 03:05 PM

 function OnTriggerEnter(otherObject : Collider){
     if(otherObject.gameObject.tag == "bonus1" && playerLives < 50){
         Destroy(otherObject.gameObject);
         playerLives += 50;
     }
     else if(otherObject.gameObject.tag == "bonus1" && playerLives >= 50){
         Destroy(otherObject.gameObject);
         playerLives = 100;
     }
 }


That should do it, I tested it and it works on my part.

Comment
Add comment · Show 3 · 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 Owen-Reynolds · Jun 19, 2011 at 03:11 PM 0
Share

$$anonymous$$ore common is to put the "what is it" check 1st, then what to do: if(tag==bonus) { if(hp<50) add50 else be100 }

avatar image PurpleHeartGames · Jun 19, 2011 at 03:15 PM 0
Share

Oh, true. Thanks for pointing that out.

avatar image Arachnos · Jun 19, 2011 at 09:24 PM 0
Share

awesome thank you

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why does if(levelToLoad ==null) not work? 2 Answers

If/else statements working one way, and not the other 0 Answers

Setting Scroll View Width GUILayout 1 Answer

not sure whats happened :S 1 Answer

Code not entering if statement. 1 Answer


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