Search Unity

Need help converting to C#

Discussion in 'Editor & General Support' started by J-F, Dec 8, 2013.

  1. J-F

    J-F

    Joined:
    Nov 8, 2012
    Posts:
    101
    I need some help to convert this to C#

    Any help would be appreciated.


    Code (csharp):
    1.     for (var touch : Touch in Input.touches)
    2.         {
    3.             if (touch.phase == TouchPhase.Stationary  gasButton.HitTest (touch.position)) {
    4.             motorInputTouch = 1;
    5.         }
    6.         else if (touch.phase == TouchPhase.Ended  gasButton.HitTest) {
    7.             motorInputTouch = 0;
    8.         }
    9.             if (touch.phase == TouchPhase.Stationary  brakeButton.HitTest (touch.position)) {
    10.             brakePower = 200;
    11.         }
    12.         else if (touch.phase == TouchPhase.Ended  brakeButton.HitTest) {
    13.             brakePower = 0;
    14.         }
    15.             if (touch.phase == TouchPhase.Stationary  leftButton.HitTest (touch.position)) {
    16.             FrontLeftWheel.steerAngle = -15.0;
    17.             FrontRightWheel.steerAngle = -15.0;
    18.         }
    19.         else if (touch.phase == TouchPhase.Ended  leftButton.HitTest) {
    20.             FrontLeftWheel.steerAngle = 0;
    21.             FrontRightWheel.steerAngle = 0;
    22.         }
    23.             if (touch.phase == TouchPhase.Stationary  rightButton.HitTest (touch.position)) {
    24.             FrontLeftWheel.steerAngle = 15.0;
    25.             FrontRightWheel.steerAngle = 15.0;
    26.         }
    27.         else if (touch.phase == TouchPhase.Ended  rightButton.HitTest) {
    28.             FrontLeftWheel.steerAngle = 0;
    29.             FrontRightWheel.steerAngle = 0;
    30.         }

    and

    Code (csharp):
    1. FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * motorInputTouch;
    2.     FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * motorInputTouch;
    3.    
    4.     BackRightWheel.brakeTorque = brakePower;
    5.     BackLeftWheel.brakeTorque = brakePower;
    6.