- Home /
Question by
thenachotech1113 · May 16, 2012 at 01:08 AM ·
playerbulletmovingissuesrespawning
player not moving after respawn(java script)
hey, i realy neeed help with this, my player is not moving after respawning,the game is playing, what can I do.
private var dead = false;
var health = 100;
var damage = 10;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if (hit.gameObject.tag == "fallout")
{
dead = true;
}
if (hit.gameObject.tag == "bullet" )
{
health -= 10;
}
if (health < 1 )
{
dead = true;
}
}
function Update()
{
if (dead)
health = 100;
transform.position = Vector3(-9,2,-48);
dead = false;
}
Comment
Best Answer
Answer by syclamoth · May 16, 2012 at 01:13 AM
Is this the script that respawns the character? Try putting braces around that 'if(dead)' bit- I've fixed up the formatting to better describe what will happen there. Without the braces around that part, it will reset the position every frame, preventing you from moving, and it will also prevent damage (because it resets the 'dead' flag every frame as well).
Try this:
function Update()
{
if (dead)
{
Debug.Log("Died, Respawning!");
health = 100;
transform.position = Vector3(-9,2,-48);
dead = false;
}
}