- Home /
Problem with Static Variable?
I have a problem with my static varible, in a collision of my projectile i call it and minus 10 for the damage the projectile does, no i don't know weather its my collision scrip that is wrong or my static var that's not picking it up
this is my collision Code
var lifespan : float= 0.6; function Awake() {
Destroy(gameObject, lifespan);
}
function OnCollisionEnter(hit : Collision) { Destroy(gameObject); if (hit.gameObject.tag == "Enemy1"){ EnemyStats.enemyHP = EnemyStats.enemyHP - 10; }
}
that code is on my projectile it should minus HP when it hits the enemy ?
Answer by Justin Warner · Jan 06, 2011 at 08:34 PM
Do a
Debug.Log("Collision works");
In to the function OnCollisionEnter...
Then in the if statement, put:
Debug.Log("Activate enemyHP Decrease");
Now run, and tell me if both, or only one comes up. Posting as answer so I can format it.
it seems like the problem is with the collision, not the HP after more testing i find i can get the HP to lower in other circumstance but not with that code attached to the variable i wonder if this is because i destroy the variable?
its not because i destroy the object, i moved the destroy code around and still no luck, even tried adding to the lifespan, How would I do a check to see if this initiated object has hit a certain tagged object?
Thanks solved it, code was right, Taggin was wrong tyvm
Okay, sorry, I was AF$$anonymous$$. Um, just so you know, if you use the Debug.Log, it'll show you where your hitting a problem. Very helpful for the future =).
thanks man :) it is what helped me out in this situation, and subsequently I marked your answer up :D