Restart Scene on button tap

After I die I want to have a touch Restart-button on Android.
I tried it in javascript, but it doesn’t work:

function OnMouseDown ()
{
Application.LoadLevel(Application.loadedLevel);
}

I read, that there should be a function update, but I don’t now how :confused:

But what is your restart button? I would guess you have this on a GameObject, GUIElement or a GameObject with a collider.

1 Answer

1

Hello, this is my first answer in this forum but AFAIK, OnMouseDown needs a box collider/circle collider(if your button is round). And you need to enter level name inside LoadLevel parenthesis

eg:
Application.LoadLevel(“level1”);

@codekidX, Application.LoadLevel has two overloads, one takes the level name by string the other takes the index of the level based off the order in build settings. [Application.loadedLevel][1] returns the index or type of int [Application.loadedLevelName][2] returns the name of the level or type of string Either can be passed to LoadLevel and the appropriate overload for the method LoadLevel will be selected by parameter type. [1]: http://docs.unity3d.com/ScriptReference/Application-loadedLevel.html [2]: http://docs.unity3d.com/ScriptReference/Application-loadedLevelName.html

Thank you sooo much! It was just the missing box collider :)