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! =)
asked Jul 20 '12 at 12:44 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:
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..