How can I have the ability to die as well as win the game at the same time?
Alright, so, I have a bug in my game currently, where I can only either win, or only die. I can't have both. I know why it does this, I have a script that is OnDestroyLoadScene, and the scene it loads is my game over scene. To win my game, you must pick up a certain amount of stones off the ground. After that, it's supposed to take you to the You Won Scene. But in doing that, it destroys everything in the current scene, and because of that it just takes me to my game over scene. Does anyone know of a workaround for this?
Answer by UnityCoach · Feb 24, 2017 at 03:58 PM
Hi, there are different ways you ask for help here. You can ask for solving an issue with a script (sharing some code) or a problem with the editor. And you can also ask for advice in regards to architecture and implementation of mechanics.
I'm saying this, as without some code, we can't really help you here. Although, I would advise not to use different scenes for "you won" and "you lose" screens. I rather have some deactivated objects that you then activate when you win/lose/pause/exit etc.
Alright so this script
function OnTriggerEnter(other : Collider){ if(other.gameObject.tag=="Obj_Char") { Destroy(gameObject); } }
is the script i've added to myself, and tagging my water as obj_char with make it so I die co$$anonymous$$g in contact with the water.
This script
function OnDestroy(){ Application.LoadLevel("Game Over $$anonymous$$enu"); }
Is the script that takes me to the game over menu when I die.
This chunk of my script
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag ( "Pick Up")) { other.gameObject.SetActive (false); count = count + 1; SetCountText (); } }
void SetCountText ()
{
countText.text = "Stones: " + count.ToString ();
if (count >= 1)
{
Application.LoadLevel("You Won Scene");
}
}
is the one that tells me how many stones I need to get, and once I get them what to do, which is load level "You Won Scene".