So i have made a script which makes my player get a "Respawn" option when his Health hits 0. But when i respawn my player the enemies the player killed are killed and they stand where they were when he died. What do i have to add to this code to make that work? Code (csharp): #pragma strict var lookAround01 : MouseLook; var lookAround02 : MouseLook; var charController : CharacterController; var respawnTransform : Transform; static var playerIsDead = false; static var enemyIsDead = false; function Start () { lookAround01 = gameObject.GetComponent(MouseLook); lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook); charController = gameObject.GetComponent(CharacterController); } function Update () { if (playerIsDead == true) { lookAround01.enabled = false; lookAround02.enabled = false; charController.enabled = false; } } function OnGUI () { if (playerIsDead == true) { if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40),"Respawn")) { RespawnPlayer(); } if (GUI.Button(Rect(Screen.width*0.5-50, 240, 100, 40),"Menu")) { Debug.Log("Return to Menu"); } } } function RespawnPlayer() { transform.position = respawnTransform.position; transform.rotation = respawnTransform.rotation; gameObject.SendMessage("RespawnStats"); lookAround01.enabled = true; lookAround02.enabled = true; charController.enabled = true; playerIsDead = false; Debug.Log("player has respawned"); } i tried the following but it didn´t work "the text in Italic is the new stuff i added" : Code (csharp): #pragma strict var lookAround01 : MouseLook; var lookAround02 : MouseLook; var charController : CharacterController; var respawnTransform : Transform; static var playerIsDead = false; [I]static var enemyIsDead = false;[/I] function Start () { lookAround01 = gameObject.GetComponent(MouseLook); lookAround02 = GameObject.Find("MainCamera").GetComponent(MouseLook); charController = gameObject.GetComponent(CharacterController); } function Update () { if (playerIsDead == true) { lookAround01.enabled = false; lookAround02.enabled = false; charController.enabled = false; } } function OnGUI () { if (playerIsDead == true) { if (GUI.Button(Rect(Screen.width*0.5-50, 200-20, 100, 40),"Respawn")) { RespawnPlayer(); } [I] { RespawnEnemy(); }[/I] if (GUI.Button(Rect(Screen.width*0.5-50, 240, 100, 40),"Menu")) { Debug.Log("Return to Menu"); } } } function RespawnPlayer() { transform.position = respawnTransform.position; transform.rotation = respawnTransform.rotation; gameObject.SendMessage("RespawnStats"); lookAround01.enabled = true; lookAround02.enabled = true; charController.enabled = true; playerIsDead = false; Debug.Log("player has respawned"); } [I]function RespawnEnemy { transform.position = respawnTransform.position; transform.rotation = respawnTransform.rotation; gameObject.SendMessage("RespawnStats"); enemyIsDead = false; Debug.Log("enemy has respawned");[/I] } Any ideas what i can do?
I'm not sure I completely understand the issue you are having but a model that I am particularly fond of is to have a script with a Reset function on every object that would need to reset itself during game play (this could also be called during initialization) and when the player dies broadcast the reset function to every object so it will have the opportunity to react. http://docs.unity3d.com/Documentation/ScriptReference/GameObject.BroadcastMessage.html
precisely, i want it to happen so when my charactre dies, it should reset EVERYTHING to it´s starter settings, such as where the enemy object is at the start.
I think you sort of missed my point . Take a look at that function in the link I gave and (probably better yet for this specific case) BroadcastMessage to set up a system where this will work easily and you'll be able to define new reset functionality in new objects without needing to keep track in some centralized location of what objects need to reset.