I’m using this code in the function Die() that is part of the ThirdPersonStatus script that is included in the 3D Platform Tutorial. The code is the very last line “PrefabUtility.ResetToPrefabState(gameObject);” but it is not working. Does it only work if I put into a Reset function? If so, how do I put a Reset function in this script and have the Die function refer to it without conflicting with the Reset function that is part of the ThirdPersonController script?? In other words, if I put SendMessage(“Reset”) won’t that now refer to the Reset function in the ThirdPersonController script and not the Reset function I put in this script? Please help! Thanks everyone!
function Die ()
{
var controller: ThirdPersonController;
controller = GetComponent(ThirdPersonController);
GetComponent(ThirdPersonController).enabled = false;
//Hide
SendMessage("HidePlayer");
// play the death sound if available.
if (vaporSound)
{
AudioSource.PlayClipAtPoint(vaporSound, transform.position);
}
if (deathSound)
{
AudioSource.PlayClipAtPoint(deathSound, transform.position);
}
yield WaitForSeconds(3.0);
lives--;
health = maxHealth;
if(lives == 0)
{
Destroy (GameObject.Find("NearCamera"));
Destroy (GameObject.Find("CSCam1"));
Destroy (GameObject.Find("CSCam2"));
Destroy (GameObject.Find("FarCamera"));
Destroy (GameObject.Find("/Level").GetComponent(GameHUD));
Application.LoadLevel("GameOver");
}
// If we've reached here, the player still has lives remaining, so respawn.
respawnPosition = Respawn.currentRespawn.transform.position;
Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up; // reset camera too
// Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
transform.position = respawnPosition + Vector3(0,0.5,0);
// give the sound time to complete.
// (NOTE: "HidePlayer" also disables the player controls.)
SendMessage("ShowPlayer"); // Show the player again, ready for...
// ... the respawn point to play it's particle effect
controller.moveSpeed = 0.0;
controller.moveDirection = Vector3.zero;
controller.speedSmoothing = 0.0;
controller.verticalSpeed = 0.0;
yield WaitForSeconds (0.5);
Respawn.currentRespawn.FireEffect ();
GetComponent(ThirdPersonController).enabled = true;
PrefabUtility.ResetToPrefabState(gameObject);
}