|
I have a score system like this: Everytime my ball enters my trigger, I get 100 points. But what if I want to get 300 points if my ball enters two triggers, or if my ball enters three triggers I get 500 points? This is my current code, which doesn't account for multiple triggers:
I hope you understand this, and maybe somebody could please help me?
(comments are locked)
|
|
Assuming that your triggers are stationary and do not get destroyed when hit: Add a class variable (call it "timeOfHit" or something) for the time and a class variable for the last trigger hit (you'll need to tag your triggers for a function... more on this later). Then when you hit a trigger record the Time (timeOfHit = Time.time;) and the tag (you'll need to have the trigger return a number or string when the function is called). On the next collision, check to see if the time is close enough to the last time (whatever you want your threshold to be) and you are hitting a different trigger. If so, give multiple points... On the player:
On the Trigger:
This should work (I haven't tested it)... the important thing is to record which trigger was hit and how long ago (if you want to make the player hit nearby triggers close together for an increased score). Thank you for your help but something dont work properly.I get the message score player.js(16,21): BCE0005: Unknown identifier: 'thisTime'.
Dec 16 '10 at 10:14 PM
Dave M
The variable should be thisHitTime in both places. I've edited the script above.
Dec 16 '10 at 11:09 PM
The_r0nin
special http://Thanks.It works fine...well done!!!
Dec 16 '10 at 11:47 PM
Dave M
Don't forget to click the checkmark to the left of the answer (so everyone will know the problem has been solved). Glad I could help.
Dec 17 '10 at 12:04 AM
The_r0nin
ok one last question maybe you could help me again....the score of the player is shown but my player is a ball (prefab) and the score will be shown correctly untill my prefab is destroyed.then the counter starts from 0. Is there a way to sum the points every prefab got in his lifetime untill he gets destroyed??
Dec 17 '10 at 12:22 AM
Dave M
(comments are locked)
|
