**I'm currently working on a car project due in 2 days, and having some issues:**
The error I'm having is:
*"CS1612(XX,25(XX represents line 59-62)): Cannot modify a type return value of 'UnityEngine.WheelCollider.sidewaysFriction'. Consider storing the value in a temporary variable"*
Here's my (C#)Code (I Used the '*' to show the error area):
using UnityEngine;
using System.Collections;
public class DriveScriptC : MonoBehaviour{
public float motorForce;
public float SteerAngle;
public WheelCollider BLWheel;
public WheelCollider BRWheel;
public WheelCollider FLWheel;
public WheelCollider FRWheel;
public float brakeForce;
public GameObject fin;
public bool CheckpointA;
public float slip;//slip of the velicle
public float hit;
public WheelFrictionCurve sidewaysFriction;
// Use this for initialization
void Start ()
{//what vars are
slip = 0;
CheckpointA = false;
fin = GameObject.FindWithTag ("Finish");
}
// Update is called once per frame
void Update () {
float v = Input.GetAxis ("Vertical") * motorForce;//
float h = Input.GetAxis ("Horizontal") * SteerAngle;//declaring var
//motor power
BLWheel.motorTorque = v;
BRWheel.motorTorque = v;
//steering
FLWheel.steerAngle = h;
FRWheel.steerAngle = h;
if (Input.GetKey (KeyCode.Space)) {//When SpaceBar is down(held), apply brake
BLWheel.brakeTorque = brakeForce;
BRWheel.brakeTorque = brakeForce;
}
if (Input.GetKeyUp (KeyCode.Space)){//When SpaceBar is up(not held), don't apply brake
BLWheel.brakeTorque = 0;
BRWheel.brakeTorque = 0;
}
*slip = 0.001 + 0.022 / (rigidbody.velocity.magnitude + 1);*
*//velocity-slip curve*
*FLWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; // X*
*FRWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; // XX*
*BLWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; // XXX*
*BRWheel.sidewaysFriction.stiffness = slip*Time.deltaTime; //XXXX*
WheelHit FLhit;
WheelHit FRhit;
WheelHit BLhit;
WheelHit BRhit;
if(FLWheel.GetGroundHit(out FLhit)){
if(FLhit.collider.gameObject.tag == "Finish"){
if(CheckpointA == true){//if Checkpoint selected
print("FINISH!");//Print "Finish"
}
}
}
if(FRWheel.GetGroundHit(out FRhit)){
if(FRhit.collider.gameObject.tag == "Finish"){
if(CheckpointA == true){//if Checkpoint selected
print("FINISH!");//Print "Finish"
}
}
}
if(BLWheel.GetGroundHit(out BLhit)){
if(BLhit.collider.gameObject.tag == "Finish"){
if(CheckpointA == true){//if Checkpoint selected
print("FINISH!");//Print "Finish"
}
}
}
if(BRWheel.GetGroundHit(out BRhit)){
if(BRhit.collider.gameObject.tag == "Finish"){
if(CheckpointA == true){//if Checkpoint selected
print("FINISH!");//Print "Finish"
}
}
}
}
}
I *do* admit, I *am* kind of a newbie...
↧