x


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 ?

more ▼

asked Jan 06 '11 at 08:31 PM

AtomicMarine gravatar image

AtomicMarine
504 42 49 70

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 06 '11 at 08:34 PM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

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?

Jan 06 '11 at 08:39 PM AtomicMarine

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?

Jan 06 '11 at 08:44 PM AtomicMarine

Thanks solved it, code was right, Taggin was wrong tyvm

Jan 06 '11 at 09:10 PM AtomicMarine

Okay, sorry, I was AFK. 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 =).

Jan 06 '11 at 10:06 PM Justin Warner

thanks man :) it is what helped me out in this situation, and subsequently I marked your answer up :D

Jan 07 '11 at 03:23 PM AtomicMarine
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2492
x653
x276

asked: Jan 06 '11 at 08:31 PM

Seen: 956 times

Last Updated: Jan 06 '11 at 08:31 PM