I have been playing around with writing my first script from scratch. Being a drag racer in the real world a nitrous controller seemed to be a good place to start. Being keen on realism and my eventual goals I did not want to just had HP.
The largest problem I am having is accessing the rpm from the drivetrain script in the CarTutorial. There are a few examples that tried from the GetComponent description page with no success. Its quite possible I am not implementing it correctly but its not from lack of effort.
Currently I receive the following error…
error CS0103: The name `rpm’ does not exist in the current context
Any help would be appreciated!
using UnityEngine;
using System.Collections;
// This class is used to simulate a nitrous system.
public class NitrousFogger : MonoBehaviour {
//This setting arms/purges the nitrous system after the burnout.
//This setting activates the nitrous system at a preset RPM range.
public float ActivateRPM = 4000;
public float DeactivateRPM = 6000;
//Nitrous parameters adjustable by user
public float NitrousOrificeSize = 0.042f;
public float NitrousPressure = 950;
//Fixed properties for nitrous flow calculation in kg m^3.
private float NitrousFlowCoefficient= 0.70f;
private float NitrousDensity = 1222.7f;
//Fuel parameters adjustable by user
public float FuelOrificeSize = .034f;
public float FuelPressure = 6.0f;
//Fixed properties for fuel flow calculation in kg m^3.
private float FuelFlowCoefficient = 0.75f;
private float FuelDensity = 715.0f;
//This activates the nitrous system.
private bool CalcActivation ()
{
bool result;
if(rpm > ActivateRPM & rpm < DeactivateRPM & Input.GetButton ("NitrousPB1"))
result = true;
else
result = false;
return result;
}
// Calculate nitrous flow
private float CalcNitrousFlowFoggerOne ()
{
float result;
if(Input.GetButton("NitrousPB1"))
result = ((((NitrousOrificeSize*NitrousOrificeSize*0.25f)*3.14159f)*NitrousFlowCoefficient)*Mathf.Sqrt(2*(NitrousPressure*689.47f)/NitrousDensity));
else
result=0;
return result;
}
// Calculate fuel flow
private float CalcFuelFlowFoggerOne ()
{
float result;
if(Input.GetButton ("NitrousPB1"))
result = ((((FuelOrificeSize*FuelOrificeSize*0.25f)*3.14159f*.00064516f)*FuelFlowCoefficient)*Mathf.Sqrt(2*FuelPressure*689.47f/FuelDensity));
else
result=0;
return result;
}
// Is nitrous flowing?
float FoggerOneNitrousFlow ()
{
float result;
if(CalcActivation ())
result = CalcNitrousFlowFoggerOne ();
else
result=0;
return result;
}
// Is fuel flowing?
float FoggerOneFuelFlow ()
{
float result;
if(CalcActivation ())
result = CalcFuelFlowFoggerOne ();
else
result=0;
return result;
}
}