- Home /
C# to Unity script question ?
Please help :) I need to convert this small piece of C# script into UnityJS ,im stuck for some reason :()
// at top of ControlledCar.cs, within the class add
public Joystick leftJS;
public Joystick rightJS;
// in Scenario select the Car and link the joysticks to the two new properties.
// in FixedUpdate function replace the steer=… accel=… brake=… lines with something like this:
steer = Mathf.Clamp(Input.GetAxis("Horizontal") + leftJS.position.x, -1f, 1f);
accel = Mathf.Clamp(Input.GetAxis("Vertical") + rightJS.position.y, -1f, 1f);
brake = Input.GetButton("Jump") || (rightJS.position.y < 0.95f);
Answer by mak · Jun 01, 2012 at 08:05 PM
ANSWERED - You have to use pragma strict for the Iphone or android my car runs perfectly now ,well it stops when its meant to lol ,.So the answer is convert all the Unity Car Tutorial to #Pragma Strict and it does actually work
Answer by Berenger · May 21, 2012 at 03:26 PM
Only two differences :
Variable declaration
C# : [protection level (default private)] [type] [name];
UnityScript : [protection level (default public)] var [name] : [type];
Floats
C# : 1f / 1.0f;
UnityScript : 1.0;
Actually you can use 1f / 1.0f in Unityscript, though there's no real reason to, since float, rather than double, is the default.
public Joystick leftJS; public Joystick rightJS;
It refuse to accept these in Js ?
Assets/Standard Assets/Scripts/Car.js(1,8): BCE0043: Unexpected token: Joystick.
Im still lost ,sorry im a noob scripter lol :p
Ok just look at what you just (should have) learned:
// C#
public Joystick leftJS;
public Joystick rightJS;
// [protection level (default private)] [type] [name];
// UnityScript
// [protection level (default public)] var [name] : [type];
public var leftJS : Joystick;
public var rightJS : Joystick;
Was that so hard? I mean that's just "token replacement".
Assets/Standard Assets/Scripts/Car.js(3,56): BCE0018: The name 'Joystick' does not denote a valid type ('not found').
is what I get now ? what am I missing please ?
Answer by mak · May 23, 2012 at 08:31 AM
I dropped the Unity Car Tutorial demo completely ,as noone knows how to stop the car moving when it shouldnt ,so its a pointless exercise ....
Your answer
![](https://koobas.hobune.stream/wayback/20220613071744im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
convert to c# 2 Answers
Converting JS to C# 3 Answers
C# to UnityScript conversion help. 0 Answers