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
What does "not working" mean? It certainly compiles without errors as long as rbody is a Rigidbody. This line should only remove the Y position constraint. I just tried it in my test project and it work as expected. An object with rigidbody and all 3 position constraints activated. The object just floats in the air. When i execute your exact line on that rigidbody it starts falling down and only the Y position contstraint was removed while x and z are still enabled. If you need further help with one of your issues, post a seperate question and add more details.
That's me not knowing java syntax. Itd be (collision : Collision) like unluckyBastard said. Not sure why the if isnt working, could you post your most up to date code?
it looks like this now var health = 5; var something : GameObject; function OnCollisionEnter(c : Collision) if (collision.gameObject == something); { health : 1};
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--;
}
}
still have the error -_- i cant see why it doesnt just read it
What does "not working" mean? It certainly compiles without errors as long as rbody is a Rigidbody. This line should only remove the Y position constraint. I just tried it in my test project and it work as expected. An object with rigidbody and all 3 position constraints activated. The object just floats in the air. When i execute your exact line on that rigidbody it starts falling down and only the Y position contstraint was removed while x and z are still enabled. If you need further help with one of your issues, post a seperate question and add more details.
– Bunny83