Question by
EliteHedgehog56 · Mar 04, 2018 at 03:09 AM ·
java to c#
convert js script into C#
I have this script that is made in javascript and I need to change it into C# so I can reference it in my player car controller script
here's the script:
var leftflames : GameObject;
var rightflames : GameObject;
var activateSound : AudioClip;
var vehicle : GameObject;
var remainingNitrous : float = 30; //make 50 the maximum amount of nitrous the player can have
static var MaxNitroCapacity : float = 30;
var CanRefill : boolean = false;
function Start () {
}
function Update () {
if (Input.GetButton("Fire1")){
if(remainingNitrous > 0){
leftflames.gameObject.active = true;
rightflames.gameObject.active =true;
}
}
if (Input.GetButtonUp("Fire1")){
leftflames.gameObject.active = false;
rightflames.gameObject.active =false;
}
if (Input.GetButtonUp("Fire1")){
if (remainingNitrous > 0){
CanRefill = true;
}
}
if (remainingNitrous == MaxNitroCapacity){
CanRefill = false;
}
if (CanRefill){
remainingNitrous +=1;
}
if (Input.GetButtonDown("Fire1")){
if (remainingNitrous > 0){
GetComponent.<AudioSource>().PlayOneShot(activateSound, 1);
}
}
if (Input.GetButton ("Fire1")){
if (remainingNitrous > 0){
Nitrous();
}
}
}
function Nitrous () {
vehicle.GetComponent.<Rigidbody>().AddForce(transform.forward * 500, ForceMode.Acceleration);
remainingNitrous -= 1;
}
Comment
Best Answer
Answer by hexagonius · Mar 04, 2018 at 07:06 AM
Variables:
Java
var name : type = value;
c#
type name = value;
Functions:
java
fuction name() {}
c#
void name() {}
Others:
Java
GetComponent.<Type>() (the dot is the difference)
gameobject.active = bool
C#
GetComponent<Type>()
gameobject.SetActive(bool)
cool thanks man, so I just go and change all the variables, functions and such to their C# version
Your answer
![](https://koobas.hobune.stream/wayback/20220612153912im_/https://answers.unity.com/themes/thub/images/avi.jpg)