- Home /
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! =)
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..
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.
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?
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!
Your answer

Follow this Question
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