I am in the middle of converting a code from javascript to C#. As seen in the below code I have four sub sequential if statements one after the other. The first of the if statement received an error saying the “if” symbol was unexpected. When I changed the statements around I discovered it always happens to the if statement that comes first, never to the ones that come after. I was wondering if anyone had ideas on how to fix this? Have i maybe missed something that needs to be in the line above? or infront?
using UnityEngine;
using System.Collections;
public class AntiRollBar : MonoBehaviour {
public int AntiRoll;
public WheelCollider WheelL;
public WheelCollider WheelR;
public WheelHit hit;
string groundedL = WheelL.GetGroundHit(hit);
string groundedR = WheelR.GetGroundHit(hit);
void FixedUpdate () {
int travelL = 1;
int travelR = 1;
int AntiRollForce = (travelL - travelR) * AntiRoll
if(groundedL)
travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
if (groundedL)
rigidbody.AddForceAtPosition(WheelL.transform.up * -AntiRollForce, WheelL.transform.position);
if (groundedR)
travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
if (groundedR)
rigidbody.AddForceAtPosition(WheelR.transform.up * AntiRollForce, WheelR.transform.position);
}
}
Thanks for any input