Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Velketor · Jul 20, 2012 at 12:44 AM · scoreplaymakeractions

Score Workflow

When enemies collide with the player, the player's hp decreases.

When enemies collide with the player's forcefield, the player's hp increases.

Which is great! but...

The players' score only increases from 0hp or decreases from 100hp. The player's score never increases or decreases based on the current score. A couple example's are below:

Example 1) Subtraction

The player has 100hp. The enemy hits the player for 10hp. Now the player has 90hp.

Example 2) Addition

Then the player activates a Forcefield; providing the player with 1hp every time the enemy collides with the Forcefield. Then the enemy enters the Forcefield and the player gains 1hp. Now the player has 1hp. WAIT...what???..ONE HIT POINT? Why does the player only have 1hp? The player should have 91hp, not 1hp. It just doesn't make sense.

This is because I have 2 variables assigned to the following integers: Score Variable 1 = 0, Score Variable 2 = 100

Then I convert these two integers into float variables: Float Variable 1 = 0, Float Variable 2 = 100

Now I convert Float Variable 1 to string a string called "Health". Then I enable a behavior that points to my GUIText and activates a seperate script called "Points". Then I compare the two integers Score Variable 1 and Score Variable 2. If Score Variable 1 is equal or less than Score Variable 2, you lose. Otherwise, the script starts over.

I am using the PlayMaker extension for Unity in combination with a few other scripts found elsewhere. That is why I cannot link the code, because I can't figure out how to get PlayMaker "actions" to be visible as actual compiled code from all actions. Anyway, that's why I gave the long explanation. For any of you who read this far, thank you for your time. Hopefully someone can answer it! =)

Comment
Add comment
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

1 Reply

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

Answer by Seth-Bergman · Jul 20, 2012 at 07:23 AM

you are adding to the variable which is set at 0, and subtracting from the var set to 100, what you want is to apply the addition or subtraction to the PLAYER'S HITPOINTS var, which will be a third var.

you start with hitpoints = 100. Then

If collide with no forcefield, simply hitpoints - 10.

now hitpoints is 90;

collide with field, hitpoints + 1. Then you could compare this hitpoints var to 0, or 100, like: if hitpoints < 0 or if hitpoints > 100

hard to be very helpful here without using code, sorry I'm not familiar with PlayMaker

EDIT(in answer to comment):

hard to say.. with a script, it would look like this:

script on the player:

 var hitpoints = 100;   
 var forcefield = false; //when forcefield is active,make this true
 
 function OnCollisionEnter(other : Collider)
 {
 if(other.tag == "enemy"){
 
 if(forcefield == true)
 hitpoints = hitpoints + 1; // if field is active, add 1
 else
 hitpoints = hitpoints - 10;
   }
 }

the function OnCollisionEnter gets entered automatically EVERY TIME my player's collider hits any other collider... Next, we use an "if" statement,

"if(other.tag == "enemy")"...

that way we won't take damage for bumping into every little thing, only objects we've tagged as "enemy"..

Every time you collide with an enemy, the hitpoints gets updated... Because again, the OnCollisionEnter function gets entered with EVERY collision. (same is true with triggers)

SO, if your collision damage is only happening the first time, it's a problem with the logic.

As you can see, so far there's no need for this calculation to be spread between TWO objects, it's all on the player.. As long as my enemy has a collider attached, and is tagged "enemy", this would work.

as for multiple triggers (on the same object), it doesn't work that way. The function "OnCollisionEnter" or "OnTriggerEnter" would only be used ONCE, but could contain as many actions as you need.. So you can use one trigger event to trigger multiple things..

Comment
Add comment · Show 5 · 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 Velketor · Jul 20, 2012 at 12:03 PM 0
Share

thank you Seth. I currently have it set up like that. However, I have them split between two seperate game objects. $$anonymous$$aybe I need to keep them all on 1 object ins$$anonymous$$d. Also, can you have multiple "enter" triggers or can you only put 1 on each object? I'm finding that Play$$anonymous$$aker ignores my commands if I put more than 1 of the same type of trigger on it. Same thing with collisions. That's the only reason I even put the scripts on 2 seperate objects (1 object has +1 script and the other has -1 script). I know it's tough to talk about with little knowledge of Play$$anonymous$$aker, but I do appreciate your help. Thanks again Seth.

avatar image Velketor · Jul 20, 2012 at 03:01 PM 0
Share

Ok so I was able to get it to read the current score and add +1. However, when it loops back, it doesn't increase +1 anymore. It only does it 1 time. Any thoughts?

avatar image Seth-Bergman · Jul 20, 2012 at 10:11 PM 0
Share

see my answer above..

avatar image Velketor · Jul 20, 2012 at 11:01 PM 0
Share

thank you Seth! I understand triggers and collisions better now. Your right about it being a problem with the logic. I moved some things around and it works now =) you have been more than helpful. big thumbs up!

avatar image Seth-Bergman · Jul 20, 2012 at 11:12 PM 0
Share

glad to help!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Score display error 1 Answer

Loading a scene and keeping original score 3 Answers

Creating a "story" for a Character 1 Answer

Javascript score problems whilst referencing scripts. 2 Answers

Score System help 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