The value of the variable suspensionForce does change in this script, but not in the objects that are linked to this array. It’s working like a copy, but I don’t want it to happen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrCarWheel : MonoBehaviour
{
[Header("Suspension")]
public Suspension[] wheelSusp;
public Vector3 forcaAntiRoll;
void Start()
{
}
void FixedUpdate()
{
float diferencaRoll = wheelSusp[0].springLength - wheelSusp[1].springLength;
float diferencaRollRear = wheelSusp[2].springLength - wheelSusp[3].springLength;
foreach (Suspension susp in wheelSusp)
{
if (susp.wheelFrontLeft)
{
wheelSusp[0].suspensionForce = wheelSusp[0].suspensionForce - diferencaRoll * wheelSusp[1].springStiffness * wheelSusp[0].vetorNormal * (float)1000000;
}
if (susp.wheelFrontRight)
{
wheelSusp[1].suspensionForce = wheelSusp[1].suspensionForce + diferencaRoll * wheelSusp[0].springStiffness * wheelSusp[1].vetorNormal * (float)1000000;
}
if (susp.wheelRearLeft)
{
wheelSusp[2].suspensionForce = wheelSusp[2].suspensionForce - diferencaRollRear * wheelSusp[3].springStiffness * wheelSusp[2].vetorNormal * (float)1000000;
}
if (susp.wheelFrontLeft)
{
wheelSusp[3].suspensionForce = wheelSusp[3].suspensionForce + diferencaRollRear * wheelSusp[2].springStiffness * wheelSusp[3].vetorNormal * (float)1000000;
}
}
}
