setting private boolen in oncollisionenter not working

Yeah i keep getting this error using this code BCE0022: Cannot convert 'boolean' to 'UnityEngine.Collision'.

    private var health = 100;
private var resetcolor = 30;
private var hit = false;
function Update () {
if (hit == true) {
resetcolor = resetcolor - 1;
renderer.material.color = Color.red;
hit = false;
}
if (resetcolor <= 0) {
renderer.material.color = Color.white;
}
if (health <= 0) {
Destroy(this);
Destroy(gameObject);
}
}

function OnCollisionEnter(hit : Collision) {
if (hit.gameObject.tag == "proj2") {
hit = true;
health = health - 50;
Destroy(hit.gameObject);
}
}

1 Answer

1

You have two variables called "hit". Either use "this.hit" to distinguish between the two, or use different variable names.