Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Converting cs to js Controll script

Discussion in 'Scripting' started by TSSTUDIOS, Dec 23, 2013.

  1. TSSTUDIOS

    TSSTUDIOS

    Joined:
    Jun 10, 2013
    Posts:
    15
    Can somone help me translate this to JS


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class V2DInputController : MonoBehaviour {
    5.  
    6.     private float h;
    7.     private Vehicle2D _vehicle = null;
    8.  
    9.     void Update() {
    10.         float  v = Input.GetAxis ("Vertical");
    11.         h = Input.GetAxis ("Horizontal");
    12.  
    13.         vehicle.SetTorque (v);
    14.  
    15.         if(Input.GetKeyDown(KeyCode.Space)) {
    16.             vehicle.StepOnBrake ();
    17.         }
    18.  
    19.         if(Input.GetKeyUp(KeyCode.Space)) {
    20.             vehicle.ReleaseWheels ();
    21.         }
    22.     }
    23.  
    24.  
    25.  
    26.     void FixedUpdate() {
    27.         vehicle.SetTilt (h);
    28.     }
    29.    
    30.    
    31.     public  Vehicle2D vehicle {
    32.         get {
    33.             if(_vehicle == null) {
    34.                 _vehicle = GetComponent<Vehicle2D> ();
    35.             }
    36.  
    37.             return _vehicle;
    38.         }
    39.     }
    40.    
    41.  
    42. }
    43.  

    basicly what i wanna add is

    Code (csharp):
    1. for (var touch in touches)
    2.                 {                          
    3.                     if(touch.phase != TouchPhase.Canceled  touch.phase != TouchPhase.Ended)
    4.                     {                                                                                          
    5.                         if(throttleTexture.HitTest (touch.position)) //if touch position is inside throttle texture
    6.                             accelerate = true;
    7.                        
    8.                         if(brakeTexture.HitTest (touch.position)) //if touch position is inside brake texture
    9.                             brake = true;
    10.                        
    11.                         if(leftTexture.HitTest (touch.position)) //left button is touched
    12.                             left = true;                       
    13.                        
    14.                         if(rightTexture.HitTest (touch.position)) //right button is touched
    15.                             right = true;                      
    16.                        
    17.                         if(left || right) //left or right button is touched
    18.                             leftORrightPressed = true;
    19.                            
    20.                         if(jumpTexture.HitTest (touch.position)) //jump button is touched
    21.                             jump = true;                       
    22.                     }
    23.                    
    24.                 }
    but i have no idea how to code in cs
     
    Last edited: Dec 23, 2013