Author Topic: Javascript causing NGUI to crash?  (Read 2504 times)

testnia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Javascript causing NGUI to crash?
« on: July 21, 2014, 11:05:49 AM »
Hi, I have been using NGUI for awhile now but I recently ran into an issue.

I was creating an Javascript to pair with NGUI interface. It works alright for the first run, but as soon as I save my workspace and relaunch Unity, NGUI fails with every NGUI associated script saying "The associated script can not be loaded. Please fix any compile errors and assign a valid script". All NGUI assets are removed from the scene as well.

But as soon as I remove the offending script from my folder, the entire thing goes back to normal.

  1. //NGU items
  2.  
  3. //var buildPanelOpen : boolean = false;
  4. //var buildPanelTweener : TweenPosition;
  5.  
  6. //Placement Plane Items
  7. var placementPlanesRoot : Transform; // attach the placement plane root
  8. var hoverMat : Material; // attach the hover material to this slot
  9. var placementLayerMask : LayerMask; // calls up the layer mask selection
  10.  
  11. private var originalMat : Material;
  12. private var lastHitObj : GameObject;
  13.  
  14. //Build Selection Items
  15. var onColor : Color;
  16. var offColor : Color;
  17. var allStructures : GameObject[];
  18. var buildBtnGraphics : UISlicedSprite[];
  19.  
  20. private var structureIndex : int = 0;
  21.  
  22. function Start ()
  23. {
  24.         //reset the structure index, refresh the GUI
  25.         //structureIndex = 0;
  26.         UpdateGUI();
  27. }
  28.  
  29. function Update ()
  30. {
  31.        
  32.                 var ray = Camera.main.ScreenPointToRay ( Input.mousePosition );
  33.                 var hit : RaycastHit;
  34.                
  35.                                 if ( Physics.Raycast ( ray, hit, 1000, placementLayerMask ) )
  36.                                 {
  37.                                         if ( lastHitObj )
  38.                                         {
  39.                                         lastHitObj.renderer.material = originalMat;
  40.                                         }
  41.                                 lastHitObj = hit.collider.gameObject;
  42.                                 originalMat = lastHitObj.renderer.material;
  43.                                 lastHitObj.renderer.material = hoverMat; // sets the planes material to the highlighted material
  44.                                 }
  45.                                
  46. else // if the raycast didn’t hit anything
  47.                 {
  48.                         if ( lastHitObj ) // if we had previously hit something
  49.                         {
  50.                         lastHitObj.renderer.material = originalMat; // visually de select that object
  51.                         lastHitObj = null; // nullify the plane selection
  52.                         }
  53.                 }
  54. }
  55.  
  56. function UpdateGUI ()
  57. {
  58. //Go through all structure buttons (buttons in the build panel). and set them to “off”
  59. for ( var theBtnGraphic : UISlicedSprite in buildBtnGraphics )
  60. {
  61. theBtnGraphic.color = offColor;
  62. }
  63. //set the selected build button to “on”
  64. buildBtnGraphics [ structureIndex ].color = onColor;
  65. }

I've inserted the code that the script contains.

Any help will be greatly appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Javascript causing NGUI to crash?
« Reply #1 on: July 21, 2014, 05:59:11 PM »
So it works fine until you restart Unity, and then Unity can't load the script? Sounds like an issue in Unity.