- Home /
 
               Question by 
               Griffo · Aug 29, 2015 at 12:22 PM · 
                uieventsystemeventsevent triggeringevent-handling  
              
 
              UnityEngine.EventSystems.. Trying to figure it out .js
Hi, I'm just starting to use the new UI GUI and are converting my scripts to use the new UI.
I've converted a C# script off the internet to .js (form HERE) but it does not do what I'd expected .. The event classes are not being called .. I've got a EventSystem in my scene.
The C# script works if I replace my .js with it.
I have no errors showing in the console.
Can someone point me in the right direction please, thanks.

 #pragma strict
 
 import UnityEngine;
 import UnityEngine.EventSystems;
 import UnityStandardAssets.CrossPlatformInput;
 
 public class Joystick extends MonoBehaviour
 {
     var MovementRange : int = 100;
     
     enum AxisOption
     {                                        // Options for which axes to use                                                     
         Both,                                // Use both
         OnlyHorizontal,                        // Only horizontal
         OnlyVertical                        // Only vertical
     }
     var axesToUse : AxisOption = AxisOption.Both;        // The options for the axes that the still will use
     var horizontalAxisName : String = "Horizontal";        // The name given to the horizontal axis for the cross platform input
     var verticalAxisName : String = "Vertical";            // The name given to the vertical axis for the cross platform input 
     
     private var startPos : Vector3;
     private var useX : boolean;                                                            // Toggle for using the x axis
     private var useY : boolean;                                                            // Toggle for using the Y axis
     private var horizontalVirtualAxis : CrossPlatformInputManager.VirtualAxis;            // Reference to the joystick in the cross platform input
     private var verticalVirtualAxis : CrossPlatformInputManager.VirtualAxis;            // Reference to the joystick in the cross platform input
     
     //              ----------------------------
     function Start () {
         
         startPos = transform.position;
         CreateVirtualAxes ();
     }
     //              ----------------------------
     function UpdateVirtualAxes (value: Vector3)
     {
         var delta = startPos - value;
         delta.y = -delta.y;
         delta /= MovementRange;
         if(useX)
             horizontalVirtualAxis.Update (-delta.x);
         
         if(useY)
             verticalVirtualAxis.Update (delta.y);
         
     }
     //              ----------------------------
     function CreateVirtualAxes()
     {
     // set axes to use
         useX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
         useY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
             
     // create new axes based on axes to use
         if (useX)
             horizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
         if (useY)
             verticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
     }
     //              ----------------------------
     function OnDrag(data: PointerEventData)
     {
         var newPos : Vector3 = Vector3.zero;
         
         if (useX) {
             var deltaX : float = (data.position.x - startPos.x);
             newPos.x = deltaX;
         }
         
         if (useY)
         {
             var deltaY : float = (data.position.y - startPos.y);
             newPos.y = deltaY;
         }
         transform.position = Vector3.ClampMagnitude( new Vector3(newPos.x , newPos.y , newPos.z), MovementRange) + startPos;
         UpdateVirtualAxes (transform.position);
     }
     //              ----------------------------
     function OnPointerUp(data: PointerEventData)
     {
         transform.position = startPos;
         UpdateVirtualAxes (startPos);
     }
     //              ----------------------------
     function OnPointerDown (data: PointerEventData)
     {
     
     }
     //              ----------------------------
     function OnDisable () {
     // remove the joysticks from the cross platform input
         if (useX)
         {
             horizontalVirtualAxis.Remove();
         }
         if (useY)
         {
             verticalVirtualAxis.Remove();
         }
     }
 }
 //              ----------------------------
 
                 
                screen-shot-2015-08-29-at-131919.png 
                (99.9 kB) 
               
 
              
               Comment
              
 
               
              Tell me, why you want to use js ?? C# is much better and powerfull language.
I agree, but I've programmed in .js a long time, and will one day learn and only program in C# but for now .js only.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                