For destroying the character after they are killed, the best way to do it, is in the life section, that signify that they have died is to put, “Destroy(gameObject,0.0)”.
That is assuming you have a health system worked out. The other way to do it, would be for you to make it so your projectile (or what ever is hurting the character) is tagged with a tag. For example, i will use ‘bullet’ as the tag:
function OnCollisionEnter() {
if (other.gameObject.tag == "bullet" ) {
Destroy(gameObject,0.0);
}
This simply says, if whatever is tagged ‘bullet’ hits the object, it will destroy itself. So simply attach this script to your enemy, or character to destroy them, and tag your weapon corresponding to the tag. You can also add tags, so you aren’t limited to the 8 or so default ones.
Now as for falling off the edge, the best way to do this, would to be make a cube, stretch it so it is bigger then your floor, delete the mesh render on it, and tag it: fallout, or what ever you want. Also, make sure you put it below your floor, so you can fall on top of it. Then attach this script to your character or who ever else you don’t want falling off.
function OnCollisionEnter() {
if (other.gameObject.tag == "fallout" ) {
Destroy(gameObject,0.0);
}
In case you didn’t notice, these are the exact same scripts, but they are so universal! You could also apply this to bullets, have it so when they have a collision they will destroy themselves instead of lying around for ever.
Good luck with your adventures! Also, just so you know, i have only be scripting/ using unity since less then a month ago, and i am decently proficient…though i do bug these guys a lot!