Does anyone know of a way to force a score keeping script to register only one point when an object is destroyed, even if the object gets hit by multiple bullets at the same time?
Sometimes when I shoot my Object that has my Keepscore script it Registers more than once when that object is destroyed.
I am thinking that the object is not being destroyed fast enough sometimes because of a lower frame rate at that time and another bullet hits that same object and registers another point. I am not sure that’s what’s happening but it sounds logical.
Here is one of my scripts that has this problem:
Thank you in advance.
Scott
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.tag == "MISSILE")
Destroy (gameObject);
KEEPSCORE_SCRIPT.score++;
Since it’s technically possible that the script gets triggered multiple times simultaneously (albeit I wouldn’t think it to be that easy as it happens in your case), what you possibly just need is a simple flag variable.
Thank you for your reply. Appears it may not be a timing problem. What else can be causing this to happen if the Timing is not doing it?
Thank you,
Scott
Here is my complete script:
var explosion : GameObject;
var beenhitalready : boolean = false;
function OnCollisionEnter(collision : Collision) {
var contact : ContactPoint = collision.contacts[0];
Most likely something like the example code at [the bottom of this MSDN page][1]. Note: I'm not sure how well this behaves in multi-monitor setups ^^. Another quick google revealed [this][2]. So GetSystemMetrics always return the resolution of the primary monitor. [1]: https://msdn.microsoft.com/en-us/library/55d3thsc.aspx [2]: https://msdn.microsoft.com/en-us/library/windows/desktop/dd162729(v=vs.85).aspx
– Bunny83