ok so im new to unity and im making an fps, this is the script i’ve made
var health = 10;
var something : GameObject;
function Update ()
{
if (OnCollisionEnter(something)) {
var health = -1;
}
}
i want to attach this to an enemy so when they collide with a bullet they will lose 1 health (i tried to put bullet instead of GameObject but it came up with an error)
when i try to build the game it says BCE0005: Unknown identifier: ‘OnCollisionEnter’
someone help plz
var health = 5;
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.name == "Bullet") //change Bullet to whatever you bullet is called, pay attention to caps.
{
health--;
}
}