- Home /
respawn delay
here's my player's health script for my splitscreen shooter I want to add a respawn delay, how do I disable the player, wait for three seconds, then enable it before transforming to spawnpoint position?
var PointCube : Transform; var spawneffect : Transform; var SpawnPoint : Transform; var respawn : boolean = false; var health:float = 90;
function Damage(dmg:float){ health -= dmg; }
function Update (){ if(health <=0){
Instantiate (PointCube,transform.position,transform.rotation);
transform.position = SpawnPoint.position;
Instantiate (spawneffect,transform.position,transform.rotation);
var audio: AudioSource = GetComponent.(); audio.Play(); audio.Play(44100);
health += 100; }
}
Answer by ownerfate · Jul 24, 2017 at 12:36 PM
The way i do a spawn delay in my game is like this.
when the player's hp hits 0, we wait 10 seconds ( your case 3 )
function Update ( ){
playerHealth();
}
function playerHealth (){
if(health == 0){
yield WaitForSeconds ( 3 );
// Do stuff
}
}
}
or you could use a InvokeRepeating () statement.
like:
function Awake(){
InvokeRepeating( "healthCheck", 0, 3 ){
}
function healthCheck (){
if(health == 0){
// do stuff
}
}
now this is good for timed events, though it starts as soon as the game starts. so you may not wait the golden 3 seconds when you wait to respawn, as it may respawn you on the 1st second.
Answer by EliteHedgehog56 · Jul 24, 2017 at 08:32 PM
ok that's pretty simple, if I added in a "set active false' in there would it negate the delay, I want to add an effect of the player dissappearing before reappearing at the spawn point 3 seconds after ( reactivating it of course)
Your answer
Follow this Question
Related Questions
Delay copy of transform position? 0 Answers
Add Delay to Moving Platform 1 Answer
How would I slow down spinning toward the mouse? 1 Answer
get bone path from transform 1 Answer