var start: Transform; // drag here the start empty object
var end: Transform; // drag here the end empty object
var duration: float = 1.6; // set duration of movement
var isNotDead:boolean=true;
var showGameOverScreenLboolean=false;
function Update(){
if(isNotDead){
// other things that you don't want the player to do while dead here
if(health<=0){
isNotDead = false;
KillPlayer();
}
}
}
function DeathCamera(){
var cam: Transform = Camera.main.transform; // get camera transform
cam.parent = null; // detach it from the player
cam.position = start.position; // place the camera at the start position
cam.LookAt(end.position); // make it look towards the end position
var t: float = 0;
while (t < 1){
t += Time.deltaTime/duration;
// move the camera towards the end position each frame
cam.position = Vector3.Lerp(start.position, end.position, t);
yield; // let Unity do other jobs til next frame
}
// movement ended - enable game over screen
showGameOverScreen = true; // enable "Game Over" message in OnGUI
}
function KillPlayer(){
DeathCamera(); // start DeathCamera coroutine
// not sure if the line below effectively stops the player...
GetComponent(CharacterController).enabled=false; //makes the player unable to move
//Other things here - showGameOverScreen is activated by DeathCamera
Screen.showCursor=true;
Screen.lockCursor=false;
}
function OnGUI(){
if(showGameOverScreen){
//GUI code with whatever you want to have at the death screen.
}
}
So I have recently gotten this awesome script. The issue I'm having is that once the camera move towards my Monster's face from death, children of the Main Camera also follow the camera. I have spotlights with a flashlight under the Main Camera, and I'm trying to null the children of the camera, which is also a child of the First Person Control Player. Of course seeing your flashlight randomly flying towards the Monster as you died looks ridiculous. Any help would be great! :)
↧