Issue with my kill counter.

Alright In my game ive used numbers for the majority of things for the moment. (Ammo, Health etc) and now decided to make a kill counter.

I used the same method for all of them though with my kill counter after one kill from 0 it goes to 1 as it should but after another kill it does not go to 2 but it stays at 1. It is probably something small that I am doing incorrectly.

Heres current parts of my script that are to do with the kill counter

public float killcount = 0f;

    if (zombiehealth <= 0)
    {
        killcounter();
        removeZombie();
    }
    if (zombiehealth <= 1)
    {
    print("kill count is now: "+killcount);
    GameObject.Find("g_Killcount").guiText.text = ""+killcount;
    }

As you can see there is an un needed zombiehealth <= 1 there, that is just me trying to work things out.

void killcounter () // killcounter
{
    killcount += 1;
}

void removeZombie () // removes the zombie
{
    if (thisIsPlayer == false)
    {
        Instantiate(ptrScriptVariable.parZombieDeath, transform.position, Quaternion.identity );
    } else {
        Instantiate(ptrScriptVariable.parPlayerDeath, transform.position, Quaternion.identity );
    }
    Destroy(gameObject);
}

I originally had killcount() code inside removeZombie but moved it to help me work things out.

I think it is something to do with my += 1; but I cannot use + 1 because I get errors or is it just me failing.

If this script is attached to each zombie, then what you have done is created a "killcount" variable for each zombie (contained in each instance), which is why in never goes higher than one. You need to declare a static/global variable in another script (perhaps on an empty gameobject to keep all your global variables) and call that variable in your zombie scripts. Then each zombie that dies will add to that one variable (rather than having a separate variable for each zombie).

For example (javascript), quickly off the top of my head:

In an object called GlobalValues with a tag "GlobalVars"

public static var killCount: int = 0;

Then on a zombie:

var globalCounter:GameObject = GameObject.FindWithTag("GlobalVars");
if (zombieHealth <= 0){
    globalCounter.killCount += 1;
    RemoveZombie();
    print("kill count is now: "+globalCounter.killCount);
}

Now you have one "killCount" variable that will add up each zombie kill...

hi can you help me quickly i used the code The_rOnin posted and i got one error which was :

Assets/Target.js(5,4): UCE0001: ';' expected. Insert a semicolon at the end

which i understand means put a ";" at the end of the line but i did and it wont go away ... look heres the code:

function Update () { var killCount; int killCount = 0; var globalCounter:GameObject = GameObject.FindWithTag("GlobalVars"); if (gameObject.Find("SmallTurret").hit) { globalCounter.killCount += 1;

print("kill count is now: "+globalCounter.killCount); }

}