- Home /
Fall Death
Im trying to kill the player via falling. Does this make sense or am i totally off?
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "FallDeath") { dead = true; } }
function Update() { if(dead) { transform.position = Vector3(0,4,0); } }
not too familiar w/ js but looks like you're using bool values for "var" which should be for numbers. try using bool type in your declare, or could do a check for 0 or 1 for your true/false check. may be some other issues, but that may get you started hopefully
In Js, var is the keyword for declaring a new variable of any type. What is missing in his declaration is the type which is not required in Js if you provide enough information for the compiler to assume the type. As he gives = false; the compiler knows it means boolean. Should he have given = 22;, the compiler makes it an integer. C# would not let you do so which makes me think you are used to C#.
Also, in C#, var is not restricted to numbers, but to any type, as long as the variable type can be deter$$anonymous$$ed at compile-time.
Oh yeah, it does. I am not really to using this one with C#...
Answer by fafase · Sep 02, 2012 at 04:29 PM
What if you try it, does it work? if it works, then it is the way but it probably does not work as you never set the dead boolean back to false so your guy is always sent back to the origin.
function Update() {
if(dead) {
transform.position = Vector3(0,4,0);
dead = false;
}
}
Your answer
Follow this Question
Related Questions
Make a script look for something an an other script 1 Answer
How can I lose health when my enemy collides with the player? 1 Answer
Environmental Death script 1 Answer
Death upon health = 0 2 Answers
Scripting a Death Fall 1 Answer