• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by importguru88 · Feb 22, 2016 at 06:56 PM · erroreditoreditor-scripting

Error BCW0012 'UnityEngine.Application.LoadLevel(String)' is obsolete. Use SceneManager.LoadScene

@script AddComponentMenu("ControlFreak-Demos-JS/DemoSwipeMenuJS")

public class DemoSwipeMenuJS extends MonoBehaviour { public var ctrl : TouchController; public var menu : SwipeMenuJS; public var guiSkin : GUISkin;

 //private var    itemWidth    : float;
 
 public var    imgFpp            : Texture2D;
 public var    imgRpg            : Texture2D;
 public var    imgMap            : Texture2D;        
 public var    imgDualStick    : Texture2D;

 public var     fadeInDuration    : float    = 1;
 private var fadeInTimer        : AnimTimer;


 private static var    MENU_SCENE_NAME            : String    = "CF-Demo-JS-Menu";
 private static var    FPP_DEMO_SCENE_NAME        : String    = "CF-Demo-JS-FPP";
 private static var    RPG_DEMO_SCENE_NAME     : String    = "CF-Demo-JS-RPG";
 private static var    MAP_DEMO_SCENE_NAME     : String     = "CF-Demo-JS-Map";
 private static var    DSS_DEMO_SCENE_NAME        : String    = "CF-Demo-JS-Dual-Stick-Shooter";
 private static var    EXIT_SCREEN_SCENE_NAME    : String     = "CF-Demo-Exit-Screen";
 
 public static var ITEM_DSS        : int    = 0;
 public static var ITEM_FPP        : int    = 1;
 public static var ITEM_RPG        : int    = 2;
 public static var ITEM_MAP        : int    = 3;
 public static var ITEM_COUNT    : int    = 4;
 
 
 
 // --------------
 static public function LoadMenuScene() : void
     {
     Application.LoadLevel(MENU_SCENE_NAME);
     }


 // ------------------
 function Start() : void
     {
     // Init swipe menu ...

     //this.itemWidth = Screen.width * 0.9f;
     this.menu.Init(ITEM_COUNT, 0, Screen.width, this.ctrl.GetDPI(), false);

     // Init fade-in timer...

     this.fadeInTimer.Start(this.fadeInDuration);
     }
 


 // ---------------
 private function StartDemo(sceneName : String) : void
     {

if UNITY_EDITOR

    if (!EditorApplication.isPlaying)
         return;

endif

     Application.LoadLevel(sceneName);
     }


 // ---------------
 function Update() : void    
     {
     // If controller's layout changed, reset menu's width...

     if ((this.ctrl != null) && this.ctrl.LayoutChanged())
         {
         this.menu.SetWindowSize(Screen.width, this.ctrl.GetDPI());
         }


     // Fade-in phase...

     if (this.fadeInTimer.Enabled)
         {
         this.fadeInTimer.Update(Time.deltaTime);
         if (this.fadeInTimer.Completed)
             this.fadeInTimer.Disable();
         }

     // Control...
     else
         {
         if (Input.GetKeyUp(KeyCode.Escape))
             {
             Application.LoadLevel(EXIT_SCREEN_SCENE_NAME);
             return;
             //Application.Quit();
             }
 
         // Get first and the only one touch zone (no need for IDs)...
 
         var zone : TouchZone = this.ctrl.GetZone(0);
 
 
         // Handle tap...
 
         if (zone.JustTapped())    
             {
             this.menu.OnTap();
             }
         
         // Handle unified-touch press...
 
         if (zone.JustUniPressed(false, false))
             this.menu.OnPress();
 
         //     If unified-touch moved, use it's drag delta...
     
         if (zone.UniDragged())
             this.menu.Move(-zone.GetUniDragDelta(TouchCoordSys.SCREEN_PX, false).x);
 
 
         // On unfied-touch release, get released drag velocity to detect those quick swipes...
 
         else if (zone.JustUniReleased(true, true))
             {
             this.menu.OnRelease(-zone.GetReleasedUniDragVel(TouchCoordSys.SCREEN_PX, false).x);        
             }
         }


     // If swipe-menu completed - go to selected mode...

     this.menu.UpdateMenu();
     if (this.menu.JustCompleted())
         {
         switch (this.menu.GetCurItem())
             {
             case ITEM_FPP : 
                 this.StartDemo(FPP_DEMO_SCENE_NAME);
                 break;
 
             case ITEM_RPG : 
                 this.StartDemo(RPG_DEMO_SCENE_NAME);
                 break;

             case ITEM_DSS : 
                 this.StartDemo(DSS_DEMO_SCENE_NAME);
                 break;
     
             case ITEM_MAP : 
                 this.StartDemo(MAP_DEMO_SCENE_NAME);
                 break;
             }

         }

     }


 // ---------------
 function OnGUI() : void    
     {
     GUI.skin = this.guiSkin;

     GUI.color = (this.fadeInTimer.Enabled ? 
         new Color(1,1,1, this.fadeInTimer.Nt) : Color.white);
 

     var topY : float = (this.fadeInTimer.Enabled ? 
         Mathf.Lerp(Screen.height, 0, this.fadeInTimer.Nt) : 0);

     var startX : float = (Screen.width * 0.5f) - (this.menu.windowSize * 0.5f) + 
         -this.menu.displayPos;
     
     var windowRect : Rect = new Rect(startX, topY, this.menu.windowSize, Screen.height * 0.66f); 
     for (var i : int = 0; i < ITEM_COUNT; ++i)
         {
         var img         : Texture2D = null;
         var descText     : String     = "";

         switch (i)
             {
             case ITEM_FPP : 
                 img = this.imgFpp; descText = FPP_DEMO_DESCRIPTION; break;
             case ITEM_RPG : 
                 img = this.imgRpg; descText = RPG_DEMO_DESCRIPTION; break;
             case ITEM_MAP : 
                 img = this.imgMap; descText = MAP_DEMO_DESCRIPTION; break;
             case ITEM_DSS : 
                 img = this.imgDualStick; descText = DSS_DEMO_DESCRIPTION; break;
             }


         var buttonScale : float = 1.0f;
         
         

         if (( this.menu.Selected()) && (i == this.menu.curItem))
             {
             buttonScale = 1.0f - Mathf.Clamp01(this.menu.GetTimeSinceSelection() / this.menu.completionDuration);
             buttonScale *= buttonScale;
             }
         else
             {
             }

         var buttonRect : Rect = windowRect;
         buttonRect.width *= buttonScale;
         buttonRect.height *= buttonScale;
         buttonRect.x = windowRect.center.x - buttonRect.width * 0.5f;
         buttonRect.y = windowRect.center.y - buttonRect.height * 0.5f;

         GUI.DrawTexture(buttonRect, img, ScaleMode.ScaleToFit);

         GUI.Box(new Rect(windowRect.x, topY + (Screen.height * 0.65f), //y + (0.6f * windowRect.height), 
             windowRect.width,  Screen.height * 0.35f), //windowRect.height * 0.35f), 
             descText);

         windowRect.x += this.menu.windowSize;
         } 
     }
 


 // --------------------
 private static var    FPP_DEMO_DESCRIPTION : String    = 
     "FPP DEMO\nDynamic Stick, tapping, dragging, etc.";

 private static var     RPG_DEMO_DESCRIPTION : String =
     "RPG DEMO\nDynamic Stick, Tap, Pinch, Canceling";

 private static var MAP_DEMO_DESCRIPTION    : String = 
     "MAP DEMO\nTwist, Pinch, Drag, Double Tap, Multi-finger Tap";

 private static var DSS_DEMO_DESCRIPTION    : String = 
     "DUAL STICK SHOOTER DEMO\nSimple Dual Sticks and Pause Button.";

 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Landern · Feb 22, 2016 at 07:04 PM

Unity changed the load scene/level code a little bit ago and will require a change.

Add an import to the header of your java/unity script that includes UnityEngine.SceneManagement.

 import UnityEngine.SceneManagement;

Replace the code that uses LoadLevel with the below.

 Line 30:
 Application.LoadLevel(MENU_SCENE_NAME);

with

 SceneManager.LoadScene(MENU_SCENE_NAME);

 And the other line 30:
 Application.LoadLevel(EXIT_SCREEN_SCENE_NAME);

with

 SceneManager.LoadScene(EXIT_SCREEN_SCENE_NAME);

 Line 3:
 Application.LoadLevel(sceneName);

with

 SceneManager.LoadScene(sceneName);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ReflexGames · Apr 12, 2016 at 04:08 AM 0
Share

Would you know how to do it with my code?

 import UnityEngine.Scene$$anonymous$$anagement;
 
 function OnTriggerEnter (col : Collider) {
 
             Debug.Log(col.gameObject.name);
             if(col.gameObject.name == "$$anonymous$$ey");
             {
                 
                 Scene$$anonymous$$anager.LoadScene(1);
               
             }
         }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Score counting works in editor but not when I build it! 0 Answers

I getting an error CS018 1 Answer

Canvas Error - Everything tinted blue 2 Answers

Cant Shoot client, Unet 0 Answers

EDITOR HOW TO GET A TEXT FILE OBJECT OR INSTANCE ID TO FOCUS THE PROJECT WINDOW ON IT 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges