LittleAngel

Restart Code in C# & JS

May 24th, 2011
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // In C#
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7.  
  8. public class RestartNow : MonoBehaviour {
  9.  
  10. void OnGUI () {
  11. if (GUILayout.Button ("Restart")) {
  12. Application.LoadLevel(Application.loadedLevel);
  13. }
  14.  
  15. if (GUI.Button (new Rect (10,30,75,20), "Restart")) {
  16. Application.LoadLevel(Application.loadedLevel);
  17. }
  18. }
  19.  
  20.  
  21. void Update () {
  22. if (Input.GetKey ("r")) {
  23. Application.LoadLevel(Application.loadedLevel);
  24. }
  25.  
  26. //Requires this button to be set in the Input Manager
  27. //http://unity3d.com/support/documentation/Manual/Input.html
  28. //http://unity3d.com/support/documentation/Components/class-InputManager.html
  29.  
  30. if (Input.GetButtonDown ("Restart")) {
  31. Application.LoadLevel(Application.loadedLevel);
  32. }
  33. }
  34. }
  35.  
  36.  
  37. // Or in UnityScript.js:
  38.  
  39. function OnGUI () {
  40. if (GUILayout.Button ("Restart")) {
  41. Application.LoadLevel(Application.loadedLevel);
  42. }
  43. if (GUI.Button (new Rect (10,30,75,20), "Restart")) {
  44. Application.LoadLevel(Application.loadedLevel);
  45. }
  46. }
  47.  
  48. function Update () {
  49. if (Input.GetKey ("r")) {
  50. Application.LoadLevel(Application.loadedLevel);
  51. }
  52.  
  53. // Requires this button to be set in the Input Manager
  54. // http://unity3d.com/support/documentation/Manual/Input.html
  55. // http://unity3d.com/support/documentation/Components/class-InputManager.html
  56.  
  57. if (Input.GetButtonDown ("Restart")) {
  58. Application.LoadLevel(Application.loadedLevel);
  59. }
  60. }
RAW Paste Data