Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Feb 17, 2013 at 08:05 PM by Eric5h5 for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Bananaman · Feb 17, 2013 at 07:47 PM · c#javascriptconvert

Can someone convert this into javascript? :)

I need help, I tried to convert this into javascript as my whole project is in javscript. I got help from someone else on how to do a swiping script and it worked perfectly. However, I need to call variables from this script from another, I'll post the c sharp script first and then my failed attempt second. The second one has a few things added to it.

 using UnityEngine;
 using System.Collections;
 
 public class Swipe : MonoBehaviour {
 
     
 void Start () 
 {
     
 }
 
 Vector2 StartPos;
 int SwipeID = -1;
 float minMovement = 20.0f;
 public GameObject gridline;
 Vector3 temp; 
 
 
 
 void Update ()
 {
 
     temp = gridline.transform.position;    
         
     foreach (var T in Input.touches) {
        var P = T.position;
        if (T.phase == TouchPhase.Began && SwipeID == -1) {
          SwipeID = T.fingerId;
          StartPos = P;
        } else if (T.fingerId == SwipeID) {
          var delta = P - StartPos;
          if (T.phase == TouchPhase.Moved && delta.magnitude > minMovement) {
           SwipeID = -1;
           if (Mathf.Abs (delta.x) > Mathf.Abs (delta.y)) {
               if (delta.x > 0) {
                  
                 //swipe right
                 if(temp.x <= 60.28 && temp.x >= 56.28)
                     {
                                 
                         if(temp.x != 60.28)
                                 {    
                          temp.x = temp.x + 1;
                          gridline.transform.position = temp;
 
                                 }
 
                     }
               } else {
                  //swipe left
                 if(temp.x <= 60.28 && temp.x >= 56.28)
                     {
                                 
                         if(temp.x != 56.28)
                                 {
                          temp.x = temp.x - 1;
                          gridline.transform.position = temp;    
 
                                 }
 
                     }
               }
           } 
           else {
               if (delta.y > 0) {
  
                  Debug.Log ("Swipe Up Found");
               } else {
  
                  Debug.Log ("Swipe Down Found");
               }
           }
          } else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
           SwipeID = -1;
        } 
     }
 }   
 }

//=====================================javascript=================================//

 wipeID : int = -1;
 var minMovement : float = 20.0f;
 public var gridline : GameObject;
 var temp : Vector3;
 var swiping : boolean = false;
 var whichdot : int = 1;
 var dot1 : GameObject;
 var dot2 : GameObject;
 var dot3 : GameObject;
 var dot4 : GameObject;
 
 
 
 function Update ()
 
 {
 
     (whichdot == 1)
         {
             dot1.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 2)
         {
             dot2.GetComponent(GUITexture).enabled = true;    
             dot1.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 3)
         {
             dot3.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot1.GetComponent(GUITexture).enabled = false;
             dot4.GetComponent(GUITexture).enabled = false;
         }
         
     if(whichdot == 4)
         {
             dot4.GetComponent(GUITexture).enabled = true;    
             dot2.GetComponent(GUITexture).enabled = false;
             dot3.GetComponent(GUITexture).enabled = false;
             dot1.GetComponent(GUITexture).enabled = false;
         }
         
 
     temp = gridline.transform.position;    
         
     for (var T in Input.touches) {
        var P = T.position;
        if (T.phase == TouchPhase.Began && SwipeID == -1) {
          SwipeID = T.fingerId;
          StartPos = P;
        } else if (T.fingerId == SwipeID) {
          var delta = P - StartPos;
          if (T.phase == TouchPhase.Moved && delta.magnitude > minMovement) {
           SwipeID = -1;
           if (Mathf.Abs (delta.x) > Mathf.Abs (delta.y)) {
               if (delta.x > 0) {
                  
                  //swipe right
                 if(temp.x <= 60.28 && temp.x >= 57.28)
                     {
                         swiping = true;
                          temp.x = temp.x + 1;
                          gridline.transform.position = temp;
                         whichdot = whichdot -1;        
                         waitalittle();
                     }
               } else {
                  //swipe left
                 if(temp.x <= 60.28 && temp.x >= 57.28)
                     {
                         swiping = true;
                          temp.x = temp.x - 1;
                          gridline.transform.position = temp;    
                         whichdot = whichdot +1;        
                         waitalittle();
                     }
               }
           } 
           else {
               if (delta.y > 0) {
  
                  Debug.Log ("Swipe Up Found");
               } else {
  
                  Debug.Log ("Swipe Down Found");
               }
           }
          } else if (T.phase == TouchPhase.Canceled || T.phase == TouchPhase.Ended)
           SwipeID = -1;
        } 
     }
 }   
     
     
 function waitalittle()
     {
         yield WaitForSeconds (1);
         swiping = false;
         
     }
 
 }
 
Comment
Add comment · Show 7
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 $$anonymous$$ · Feb 17, 2013 at 07:52 PM 0
Share

whats wrong the the javascript? do you get compilation errors or other oddities?

avatar image Bananaman · Feb 17, 2013 at 07:59 PM 0
Share

No compilition errors, just when I compile and run it on my android, it no longer works.

avatar image Eric5h5 · Feb 17, 2013 at 08:04 PM 0
Share

This isn't really the place; "Please do work for me" isn't the purpose of this site. It's for asking specific development questions.

avatar image Bananaman · Feb 17, 2013 at 08:07 PM 0
Share

That is why I put my attempt below??? so people could help me solve the problem...

avatar image Eric5h5 · Feb 17, 2013 at 08:12 PM 1
Share

If you went on StackOverflow and asked someone to convert a script to a different language, it would also be closed. This site is basically StackOverflow for Unity, so please use it in the same way. I'd suggest posting in the forums for this sort of thing.

Show more comments

1 Reply

  • Sort: 
avatar image
-1

Answer by BoomBetStudios · Feb 17, 2013 at 10:49 PM

http://forum.unity3d.com/threads/46520-Online-UnityScript-Javascript-to-C-converter

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 Eric5h5 · Feb 18, 2013 at 12:35 AM 1
Share

That's the opposite of what the question is asking.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

How can I change this C# code into Javascript? 0 Answers

Need help converting javascript to c# script 2 Answers

Help converting C# to Javascript. 1 Answer

How to make this line work in C#? 1 Answer

Javascript int to float 1 Answer


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