Problem accessing a changed variable from another script

I’m creating a damage delivery system that has a deliverer and a receiver, on the deliverer’s side I have a penetration value that decreases by 0.7 every frame, like this:

var Penetration = 100.0;

function Update () {

Penetration -= 0.7;

}

Now, when it hits the target, the receiver script should obtain the penetration value from the deliverer, I thought it is going to be simple but its not working the way I hope it would, the receiver somehow get the full 100 penetration value every time and not a reduced value. The script looks like this:

var Deliverer : GameObject;

var PenetrationDamage = 0.0;

function Start () {

PenetrationDamage = Deliverer.GetComponent(“DelivererScript”).Penetration;

}

The projectile even stayed in the air for 2 seconds before impact and should have like 66 penetration. I really have no idea why the receiver keeps getting the original 100 penetration and not the reduced penetration… would appreciate some help here, thanks in advance for any response!

Ben

You are taking the value of Penetration in Start() which happens once, before all of the Update() calls. Do you now want to take the value when something actually happens?

Try to do an OnCollision or function call when the projectile hits its target. Have the target figure out what projectile hit it, then have an accessor function for the variable that just returns the variable. Try not to access variables through public unless they are on the same object (like a child/parent relationship). He is right though, you get the penetration value in the start() function, try to retrieve the penetration value when the collision occurs (as then the penetration value wont be 100 as it is at begin of frame when start() is called).

So the problem is the fact that function Start happens before function Update…now I get why it isn’t working! Thanks mate!

Ben