Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
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.

alt text

 #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
Add comment · Show 2
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 RafiXWPT · Aug 29, 2015 at 12:45 PM -1
Share

Tell me, why you want to use js ?? C# is much better and powerfull language.

avatar image Griffo · Aug 29, 2015 at 01:00 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Griffo · Aug 29, 2015 at 03:51 PM

Correct answer given HERE ..

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

30 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

Related Questions

How to pass a click through a button? 1 Answer

Unity 2019.3 any way to make mouse events pass thru an UI element without disabling "Raycast Target" ? 2 Answers

Triggering events for overlaying UI Elements. 0 Answers

Parent Event Handler Overriding Child Handler 0 Answers

Catch pointer events by multiple gameObjects 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges