Weird Int Value

Hi,

I made a script

using UnityEngine;
using System.Collections;

public class MultiKill : MonoBehaviour {

public int Kill = 0;
    public AudioSource DoubleKill;
	
	// Update is called once per frame
	void Update ()
    {
        if (Kill == 2)
        {
            DoubleKill.Play();
        }
        else { }

        
	}
}

I use another script on my AI that when health <= 0 Kill += 1;

i also got a timer which check after an enemy has been killed that the kill == 0

When i start the game and i kill 2 enemies, so the count is 2, then nothing happens.
when the timer comes in and set the 2 to 0 then the Doublekill music plays :S

when i shoot 3 enemies and the count is 3 the Doublekill music also plays.

What am i doing wrong here?

// Update is called once per frame

The small script which you posted is totally fine, executing Play() when Kill is 2. As you did not post the other script, which would have been more important in my humble opinion, the following is just an educated guess:

If Kill is 2, then your Play() is executed every single frame, so the audio is probably restarted endlessly, so you don’t hear anything. If kill is moved away from 2, then the sound gets enough time to play in peace.

So you should probably just reset Kill to 0 right before calling DoubleKill.Play().