void Awake() { if (!wheelModel) { Debug.LogError(transform.name + " wheel of the " + drivetrain.transform.name + " is missing wheel model. This wheel is disabled"); enabled = false; return; } rigid = GetComponentInParent <Rigidbody>(); drivetrain = GetComponentInParent <SCC_Drivetrain> (); wheelCollider = GetComponent <WheelCollider>(); wheelCollider.mass = rigid.mass / 25f; GameObject fixedModel = new GameObject(wheelModel.name); fixedModel.transform.position = wheelModel.position; fixedModel.transform.SetParent(rigid.transform); fixedModel.transform.localRotation = Quaternion.identity; fixedModel.transform.localScale = Vector3.one; foreach (Transform go in wheelModel.GetComponentsInChildren <Transform>()) { go.SetParent(fixedModel.transform); } wheelModel = fixedModel.transform; }
void Start() { drivetrain = GetComponent <SCC_Drivetrain> (); inputs = GetComponent <SCC_Inputs> (); car = GetComponent <Transport>(); GameObject engineOnGO = new GameObject("Engine On AudioSource"); engineOnGO.transform.SetParent(transform, false); engineOnSource = engineOnGO.AddComponent <AudioSource> (); engineOnSource.clip = engineOn; engineOnSource.loop = true; engineOnSource.spatialBlend = 1f; engineOnSource.Play(); GameObject engineOffGO = new GameObject("Engine Off AudioSource"); engineOffGO.transform.SetParent(transform, false); engineOffSource = engineOffGO.AddComponent <AudioSource> (); engineOffSource.clip = engineOff; engineOffSource.loop = true; engineOffSource.spatialBlend = 1f; engineOffSource.Play(); }
public override void OnInspectorGUI() { serializedObject.Update(); driveTrainScript = (SCC_Drivetrain)target; defaultGUIColor = GUI.color; //EditorGUILayout.PropertyField (serializedObject.FindProperty ("wheelModels"), true); EditorGUILayout.Space(); wheels = driveTrainScript.wheels; float defaultLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100f; if (wheels != null) { for (int i = 0; i < wheels.Length; i++) { EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Wheels " + i.ToString(), EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUI.color = Color.red; if (GUILayout.Button("X")) { RemoveWheel(i); } GUI.color = defaultGUIColor; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); wheels [i].wheelTransform = (Transform)EditorGUILayout.ObjectField("Wheel Model", wheels [i].wheelTransform, typeof(Transform), true); wheels [i].wheelCollider = (SCC_Wheel)EditorGUILayout.ObjectField("Wheel Collider", wheels [i].wheelCollider, typeof(SCC_Wheel), true); if (wheels [i].wheelCollider == null) { GUI.color = Color.cyan; if (GUILayout.Button("Create WheelCollider")) { WheelCollider newWheelCollider = SCC_CreateWheelCollider.CreateWheelCollider(driveTrainScript.gameObject, wheels [i].wheelTransform); wheels [i].wheelCollider = newWheelCollider.gameObject.GetComponent <SCC_Wheel> (); wheels [i].wheelCollider.wheelModel = wheels [i].wheelTransform; Debug.Log("Created wheelcollider for " + wheels [i].wheelTransform.name); } GUI.color = defaultGUIColor; } EditorGUILayout.EndHorizontal(); EditorGUIUtility.labelWidth = 20f; EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(GUI.skin.button); wheels [i].isSteering = EditorGUILayout.ToggleLeft("Steering", wheels [i].isSteering); wheels [i].isTraction = EditorGUILayout.ToggleLeft("Traction", wheels [i].isTraction); wheels [i].isBrake = EditorGUILayout.ToggleLeft("Brake", wheels [i].isBrake); wheels [i].isHandbrake = EditorGUILayout.ToggleLeft("Handbrake", wheels [i].isHandbrake); EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); if (wheels [i].isSteering) { wheels [i].steeringAngle = EditorGUILayout.Slider("Steer Angle", wheels [i].steeringAngle, -45f, 45f); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUIUtility.labelWidth = 100f; } } GUI.color = Color.green; EditorGUILayout.Space(); if (GUILayout.Button("Create New Wheel Slot")) { AddNewWheel(); } GUI.color = defaultGUIColor; EditorGUILayout.Space(); EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel); EditorGUILayout.Space(); EditorGUIUtility.labelWidth = defaultLabelWidth; EditorGUILayout.PropertyField(serializedObject.FindProperty("COM")); EditorGUILayout.PropertyField(serializedObject.FindProperty("engineTorque")); EditorGUILayout.PropertyField(serializedObject.FindProperty("brakeTorque")); EditorGUILayout.PropertyField(serializedObject.FindProperty("maximumSpeed")); EditorGUILayout.PropertyField(serializedObject.FindProperty("finalDriveRatio")); EditorGUILayout.PropertyField(serializedObject.FindProperty("highSpeedSteerAngle")); EditorGUILayout.PropertyField(serializedObject.FindProperty("direction")); if (GUI.changed) { EditorUtility.SetDirty(driveTrainScript); } serializedObject.ApplyModifiedProperties(); }
void Start() { drivetrain = GetComponent <SCC_Drivetrain> (); car = GetComponent <Transport>(); }