weapon leveling

I"m tryign to make a game that has a simliar leveling system to COD and BFBC2. In sort, if you don’t know, when a you use weapon X and “enemy” is killed, you get exp and the weapon X you used get a certina amount of exp.
Here is what I have attached to my " enemy":

var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;
var deadbyplayer = false;
var dead = false;
var deadbyAI = false;
var flamehit = false;
var burntime = 5;
var hitbyplayerremington8 = false;

function OnControllerColliderHit(hit : ControllerColliderHit)
{
	if(hit.gameObject.tag == "playerflame")
{
		flamehit = true;
}

if(hit.gameObject.tag == "playerRemingtion8bullet")
{
		hitbyplayerremington8 = true;
}
}

function ApplyDamage (damage : float) {
	// We already have less than 0 hitpoints, maybe we got killed already?
	if (hitPoints <= 0.0)
	
		return;
		
		hitPoints -= damage;
		
		if (hitPoints <= 0.0)
		{
	playerscore.TeamAscore +=1;
		dead = true;
}

	if (hitPoints <= 0.0 && hitbyplayerremington8 == true)
	{
	MyFPS.CURRENTEXP +=1;
	Playerprofile.CURRENTEXP +=1;
	Playerprofile.KILLS +=1;
	playerscore.TeamAscore +=1;
	Remingtion8.FIELDPOINTS +=1
	Playerprofile.Money +=5;
	hitbyplayerremington8 = false;
	deadbyplayer = true;
	}
	
	if (hitPoints <= 0.0 && flamehit == true)
{
MyFPS.CURRENTEXP +=1;
Playerprofile.CURRENTEXP +=1;
Playerprofile.KILLS +=1;
playerscore.TeamAscore +=1;
flamethrower.FIELDPOINTS +=1;
Playerprofile.Money +=5;
flamehit = false;
deadbyplayer = true;
		
}	
}
static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
	dst.position = src.position;
	dst.rotation = src.rotation;
	
	for (var child : Transform in dst) {
		// Match the transform with the same name
		var curSrc = src.Find(child.name);
		if (curSrc)
			CopyTransformsRecurse(curSrc, child);
	}
}
function LateUpdate () {
if (deadbyplayer) {
hitPoints = 100.0;
transform.position = Vector3(16,6,-40);
deadbyplayer = false;
}

if(dead)
{
hitPoints = 100.0;
transform.position = Vector3(16,6,-40);
dead = false;
}
if(hitbyplayerremington8) {

WaitForSeconds(5);
 hitbyplayerremington8 = false;
}
if(flamehit)
		{
		WaitForSeconds(burntime);
		
		
			flamehit = false;
		}
}

What did I do wrong? Any good resources to look at? Note: I do get the exp on the gun / player / other codes to work when I only have this
(hitPoints <= 0.0)
and jam all the other codes under it.

ok. I figured it out :slight_smile:

I need to have the true statements under LateUpdate.
So if you want the code it’s :

put this on your “enemy”:

 var hitPoints = 100.0;
    var dieSound : AudioClip;
    var dead = false;
    var deadbyAI = false;
    var hitbyplayerremington8 = false;
    
    function OnControllerColliderHit(hit : ControllerColliderHit)
    {
    
    if(hit.gameObject.tag == "playerRemingtion8bullet")
    {
    		hitbyplayerremington8 = true;
    }
    }
    
    function ApplyDamage (damage : float) {
    	// We already have less than 0 hitpoints, maybe we got killed already?
    	if (hitPoints <= 0.0)
    	
    		return;
    		
    		hitPoints -= damage;
    		
    		if (hitPoints <= 0.0)
    		{
    	playerscore.TeamAscore +=1;
    		dead = true;
    }
    	
    }
    function LateUpdate () 
``{    
    if(dead && hitbyplayerremington8 == true)
    {
    	MyFPS.CURRENTEXP +=1;
    Playerprofile.CURRENTEXP +=1;
    Playerprofile.KILLS +=1;
    playerscore.TeamAscore +=1;
    Remingtion8.FIELDPOINTS +=1;
    Playerprofile.MONEY +=5;
    hitbyplayerremington8 = false;
    
    hitPoints = 100.0;
    transform.position = Vector3(16,6,-40);
    dead = false;
    }
    else if (dead)
    {
    hitPoints = 100.0;
    transform.position = Vector3(16,6,-40);
    dead = false;
    
    }
    }

and this on your “weapon” :

static var REMINGTON8LEVEL = 0;
public var remington8level : int =0;
static var FIELDPOINTS = 0;
public var fieldpoints : int =0;
public var fpmax = 10;
private var startfp = 0;
private var fpmuilt = 1.5;
var levelup = false;
function Update () {
remington8level = REMINGTON8LEVEL;
fieldpoints = FIELDPOINTS;
if(FIELDPOINTS >= fpmax) {
 levelup = true;
 }
}
function LateUpdate () {
	if (levelup) {
	REMINGTON8LEVEL +=1;
fpmax = fpmax * fpmuilt;
FIELDPOINTS = startfp;
levelup = false;
	}

hope this helps someone out :slight_smile: