- Home /
Death on Lava collision
Translation: I'm not a really good programmer and I'm trying to make my character 'die' when he falls on lava. How would I go forth doing this?
Original Message:
i am making a game where if the character touches the lava he dies...now i am horrible...HORRIBLE with scripting for right now so i really need help with how to do this...PLEASE HELP!!!
Geez, when I read that title I thought someone was gonna get killed!!!!!!!!!!!!!!!!!!!!!!
What I'm saying is, I remember when you were really good at using your batputer. It's time to move on to cursing the kids on the Wayne $$anonymous$$anor lawn, old-timer.
Answer by robertmathew · Apr 13, 2011 at 12:42 PM
// A grenade // - instantiates a explosion prefab when hitting a surface // - then destroys itself
var explosionPrefab : Transform;
function OnCollisionEnter(collision : Collision) { // Rotate the object so that the y-axis faces along the normal of the surface var contact : ContactPoint = collision.contacts[0]; var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal); var pos : Vector3 = contact.point; Instantiate(explosionPrefab, pos, rot); // Destroy the projectile Destroy (gameObject); }
http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
http://unity3d.com/support/documentation/ScriptReference/Object.Destroy.html
Answer by Simon V · May 24, 2011 at 03:27 PM
If you have the code in place for your character dieing, you only got to call that function.
So basically you would create something like:
private void CheckDeath(int Hp)
{
if (hp = 0)
{
-execute wathever code you have for dieing, could be a message, together with a red overlay on the screen. And code to revive-
}
}
And then for the touching itself, you would need a collider, but I haven't worked with those yet. (The basics should be in the link Robert posted.)
Your answer
Follow this Question
Related Questions
Health, Death and respawn help 3 Answers
unity 3d enemy that shoots at you and gets killed 5 Answers
How to Make a "Kill Platform"? 1 Answer