Hello!
Im trying to change a variable with my fuel script in the car controller script to give 0 engine torque when out of fuel.
But im not sure how to do that.
Heres what i got so far
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
[RequireComponent(typeof (CarController))]
public class Fuel1 : MonoBehaviour {
public CarController CarController; //to add the actually script
public Text text;
public float Gas;
float KPL;
Vector3 LastPosition;
Vector3 CurrentPosition;
float change;
// Use this for initialization
void Start () {
LastPosition = transform.position;
CurrentPosition = transform.position;
change = 0f;
Gas = 80f;
KPL = 10f;
}
void FixedUpdate () {
text.text = Gas.ToString("00.0") + "L";
CurrentPosition = transform.position;
float change = Vector3.Distance(CurrentPosition, LastPosition);
change = change * 0.009f;
Gas = Gas - change /KPL;
LastPosition = CurrentPosition;
//from here it needs to change the engine torque
if(Gas <= 0)
{
engineTorque = 0f;
Gas = 0f;
}
else
{
engineTorque = 1400f;
}
}
}
It says “engineTorque” dont exist in the current contet" witch means that i missing something in this script to make the script find it?