private void ChangeCar() { Destroy(character); //Debug.LogWarning("Destroy(character); ChangeCar()"); character = Instantiate(enemyCar[currentCar].CarPrefab, carGaragePos.position, Quaternion.identity) as GameObject; if (character != null) { character.transform.parent = podium; AxisCarController tractorACC = character.GetComponentInChildren <AxisCarController>(); tractorACC.InStation = true; if (raceStart != null)//из меню станции { raceStart.axisCarController = tractorACC; } character.GetComponentInChildren <AxisCarController>().MaxSpeed = enemyCar[currentCar].MaxSpeed; SetTunningButtons(character.GetComponentInChildren <CameraTarget>()); } buttonUpgradeCar.gameObject.SetActive(enemyCar[currentCar].HasBought); buttonRace2.gameObject.SetActive(enemyCar[currentCar].HasBought); buttonBuyCar.gameObject.SetActive(!enemyCar[currentCar].HasBought); priceIndicator.text = enemyCar[currentCar].Price.ToString("f0"); nameIndicator.text = enemyCar[currentCar].TruckName; if (!enemyCar[currentCar].HasBought) { ResetTunning(); ShowInfoMenu(); StartCoroutine(UpdateMaxSpeedIndicator(0.05f)); } else { StartCoroutine(ReadRegParam(0.05f)); } }
void Start () { drivetrain = transform.parent.GetComponent<Drivetrain>(); axisCarController = transform.parent.GetComponent<AxisCarController>(); if (smokes.Length > 0) velocityZ = smokes[0].localVelocity.z; }
/// <summary> /// Constructor. /// </summary> /// <param name="go">Vehicle game object.</param> public GameVehicle(GameObject go) { gameObject = go; dynamics = gameObject.GetComponent <CarDynamics>(); Client.Assert(dynamics != null, "Missing car dynamics!"); driveTrain = gameObject.GetComponent <Drivetrain>(); axisCarController = gameObject.GetComponent <AxisCarController>(); mpCarController = gameObject.AddComponent <MPCarController>(); PlayMakerFSM[] fsms = gameObject.GetComponentsInChildren <PlayMakerFSM>(); foreach (var fsm in fsms) { if (fsm.FsmName == "PlayerTrigger") { SetupPlayerTriggerHooks(fsm); // Temp - use player trigger.. seatGameObject = fsm.gameObject; } } }
void Start() { drivetrain = transform.parent.GetComponent <Drivetrain>(); axisCarController = transform.parent.GetComponent <AxisCarController>(); if (smokes.Length > 0) { velocityZ = smokes[0].localVelocity.z; } }
void Start() { if (brakeLights == null) { brakeLights = GetComponent <BrakeLights>(); } if (drivetrain == null) { drivetrain = GetComponent <Drivetrain>(); } if (aerodynamicResistance == null) { aerodynamicResistance = GetComponent <AerodynamicResistance>(); } if (soundController == null) { soundController = GetComponent <SoundController>(); } if (carDynamics == null) { carDynamics = GetComponent <CarDynamics>(); } if (axles == null) { axles = GetComponent <Axles>(); } if (axisCarController == null) { axisCarController = GetComponent <AxisCarController>(); } if (carDamage == null) { carDamage = GetComponent <CarDamage>(); } if (arcader == null) { arcader = GetComponent <Arcader>(); } if (setup == null) { setup = GetComponent <Setup>(); } if (bodyRb == null) { bodyRb = GetComponent <Rigidbody>(); } if (camerasController == null) { camerasController = GetComponent <CamerasController>(); } }
void SetComponent(){ drivetrain = GetComponent<Drivetrain>(); cardynamics = GetComponent<CarDynamics>(); forceFeedback= GetComponent<ForceFeedback>(); physicMaterials =GetComponent<PhysicMaterials>(); arcader= GetComponent<Arcader>(); aerodynamicResistance= GetComponent<AerodynamicResistance>(); axles= GetComponent<Axles>(); axisCarController = GetComponent <AxisCarController>(); mouseCarController = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); fuelTanks=GetComponentsInChildren<FuelTank>(); wings=GetComponentsInChildren<Wing>(); }
/// <summary> /// Constructor. /// </summary> /// <param name="go"></param> public PlayerVehicle(GameObject go, ObjectSyncComponent osc) { gameObject = go; syncComponent = osc; ParentGameObject = go.transform.parent.parent.gameObject; rigidbody = ParentGameObject.GetComponent <Rigidbody>(); dynamics = ParentGameObject.GetComponent <CarDynamics>(); driveTrain = ParentGameObject.GetComponent <Drivetrain>(); axisCarController = ParentGameObject.GetComponent <AxisCarController>(); mpCarController = ParentGameObject.AddComponent <MPCarController>(); FindFSMs(); }
public override void OnLoad() { AssetBundle ab = AssetBundle.CreateFromMemoryImmediate(Properties.Resources.edm); edm = GameObject.Instantiate(ab.LoadAsset <GameObject>("EDM.prefab")); ab.Unload(false); saveManager = edm.GetComponent <SaveManager>(); GameObject.DestroyImmediate(MenuColls); saveManager.Load(); acc = edm.GetComponent <AxisCarController>(); drivetrain = edm.GetComponent <Drivetrain>(); GameObject Shadow = GameObject.Instantiate(GameObject.Find("NPC_CARS").transform.Find("KUSKI/LOD/CarShadowProjector 3").gameObject); Shadow.transform.SetParent(edm.transform); Shadow.transform.localPosition = new Vector3(0f, 0.54f, -0.2f); Shadow.transform.localEulerAngles = new Vector3(90f, 90f, 0f); Shadow.transform.localScale = Vector3.one; Shadow.name = "CarShadowProjector"; edm.AddComponent <CollisionSound>(); //copy physics materials from hayosiko (can be any other car). (To know on what surface it will be driving) edm.GetComponent <CarDynamics>().physicMaterials = GameObject.Find("HAYOSIKO(1500kg, 250)").GetComponent <CarDynamics>().physicMaterials; //Add some skidmarks from hayosiko edm.GetComponent <CarDynamics>().skidmarks = GameObject.Find("HAYOSIKO(1500kg, 250)").GetComponent <CarDynamics>().skidmarks; #region Set up Lifts DrunkGuyLiftHandler liftHandler = edm.transform.Find("DrivingDoors").gameObject.AddComponent <DrunkGuyLiftHandler>(); liftHandler.rightDoor = edm.transform.Find("DrivingDoors/Doors/saloon_front_door_right").GetComponent <Door>(); liftHandler.driveTrigger = edm.transform.Find("PlayerTrigger/DriveTrigger").GetComponent <PlayerDriveTrigger>(); DrunkGuyMovingHandler movingHandler = edm.transform.Find("DrivingDoors").gameObject.AddComponent <DrunkGuyMovingHandler>(); movingHandler.rightDoor = edm.transform.Find("DrivingDoors/Doors/saloon_front_door_right").GetComponent <Door>(); movingHandler.driveTrigger = edm.transform.Find("PlayerTrigger/DriveTrigger").GetComponent <PlayerDriveTrigger>(); #endregion GameOptions(); //edm.transform.Find("RainScript").gameObject.AddComponent<windshieldUVadjuster>(); }
/// <summary> /// Constructor. /// </summary> /// <param name="go"></param> public PlayerVehicle(GameObject go, ObjectSyncComponent osc) { gameObject = go; syncComponent = osc; ParentGameObject = go.transform.parent.parent.gameObject; if (ParentGameObject.name.StartsWith("JONNEZ")) { isBike = true; steeringPivot = ParentGameObject.transform.FindChild("LOD/Suspension/Steering/SteeringPivot").gameObject; } rigidbody = ParentGameObject.GetComponent <Rigidbody>(); dynamics = ParentGameObject.GetComponent <CarDynamics>(); driveTrain = ParentGameObject.GetComponent <Drivetrain>(); axisCarController = ParentGameObject.GetComponent <AxisCarController>(); mpCarController = ParentGameObject.AddComponent <MPCarController>(); AddVehicleDoorSync(); FindFSMs(); }
public HandThrottle(string throttlePath) { try { drivetrain = gameObject.GetComponent <Drivetrain>(); axisCarController = gameObject.GetComponent <AxisCarController>(); } catch { throw new Exception("HandThrottle: Components not found."); } try { Transform handThrottle = transform.Find(throttlePath); handThrottleValue = handThrottle.GetPlayMakerFSM("Use").FsmVariables.GetFsmFloat("Throttle"); handThrottle.GetPlayMakerFSM("Throttle").enabled = false; } catch { throw new Exception("HandThrottle: FSM tweaks issue."); } }
void Awake() { body = GetComponent <Rigidbody>(); originalCenterOfMass = body.centerOfMass; myTransform = transform; drivetrain = GetComponent <Drivetrain>(); axisCarController = GetComponent <AxisCarController>(); mouseCarcontroller = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); brakeLights = GetComponent <BrakeLights>(); dashBoard = myTransform.GetComponentInChildren <DashBoard>(); steeringWheel = transform.GetComponentInChildren <SteeringWheel>(); soundController = GetComponent <SoundController>(); SetController(controller.ToString()); axles = GetComponent <Axles>(); //frontWheels=axles.frontAxle.wheels; //rearWheels=axles.rearAxle.wheels; //otherWheels=axles.otherWheels; //axles.allWheels=axles.axles.allWheels; invAllWheelsLength = 1f / axles.allWheels.Length; fixedTimeStepScalar = 0.02f / Time.fixedDeltaTime; invFixedTimeStepScalar = 1 / fixedTimeStepScalar; }
public void SetController(string strcontroller){ axisCarController = GetComponent <AxisCarController>(); // to make this function works with SaveSetup() mouseCarcontroller = GetComponent <MouseCarController>(); // to make this function works with SaveSetup() mobileCarController = GetComponent <MobileCarController>(); // to make this function works with SaveSetup() if (strcontroller==Controller.axis.ToString() ) { if (axisCarController==null){ axisCarController=transform.gameObject.AddComponent<AxisCarController>(); } axisCarController.enabled=true; carController=axisCarController; if (drivetrain!=null) drivetrain.carController=axisCarController; if (brakeLights!=null) brakeLights.carController=axisCarController; if (dashBoard!=null) dashBoard.carController=axisCarController; if (steeringWheel!=null) steeringWheel.carController=axisCarController; if (soundController!=null) soundController.carController=axisCarController; if (mouseCarcontroller!=null) mouseCarcontroller.enabled=false; if (mobileCarController!=null) mobileCarController.enabled=false; controller=Controller.axis; } else if (strcontroller==Controller.mouse.ToString()){ if (mouseCarcontroller==null){ mouseCarcontroller=transform.gameObject.AddComponent<MouseCarController>(); } mouseCarcontroller.enabled=true; mouseCarcontroller.smoothInput=false; carController=mouseCarcontroller; if (drivetrain!=null) drivetrain.carController=mouseCarcontroller; if (brakeLights!=null) brakeLights.carController=mouseCarcontroller; if (dashBoard!=null) dashBoard.carController=mouseCarcontroller; if (steeringWheel!=null) steeringWheel.carController=mouseCarcontroller; if (soundController!=null) soundController.carController=mouseCarcontroller; if (axisCarController!=null) axisCarController.enabled=false; if (mobileCarController!=null) mobileCarController.enabled=false; controller=Controller.mouse; } else if (strcontroller==Controller.mobile.ToString()){ if (mobileCarController==null){ mobileCarController=transform.gameObject.AddComponent<MobileCarController>(); } mobileCarController.enabled=true; carController=mobileCarController; if (drivetrain!=null) drivetrain.carController=mobileCarController; if (brakeLights!=null) brakeLights.carController=mobileCarController; if (dashBoard!=null) dashBoard.carController=mobileCarController; if (steeringWheel!=null) steeringWheel.carController=mobileCarController; if (soundController!=null) soundController.carController=mobileCarController; if (axisCarController!=null) axisCarController.enabled=false; if (mouseCarcontroller!=null) mouseCarcontroller.enabled=false; controller=Controller.mobile; } else if (strcontroller==Controller.external.ToString() ){ if (mouseCarcontroller!=null) {mouseCarcontroller.throttle=drivetrain.throttle=0;mouseCarcontroller.enabled=false;} if (axisCarController!=null) {axisCarController.throttle=drivetrain.throttle=0;axisCarController.enabled=false;} if (mobileCarController!=null) {mobileCarController.throttle=drivetrain.throttle=0;mobileCarController.enabled=false;} controller=Controller.external; } }
private void Race()//ButtonRace { PlayerPrefs.SetInt("CurrentCar", currentCar); character.transform.parent = null; if (PlayerPrefs.HasKey("StartCarPos")) { if (first) { character.transform.position = carLevelPos[PlayerPrefs.GetInt("StartCarPos")].position; character.transform.rotation = carLevelPos[PlayerPrefs.GetInt("StartCarPos")].rotation; Debug.Log("Start from " + PlayerPrefs.GetInt("StartCarPos") + " town"); } else//Из гаража { character.transform.position = beforeGaragePosition; character.transform.rotation = beforeGarageRotation; Debug.Log("Start from Garage"); } } else//Первый запуск { character.transform.position = carLevelPos[0].position; character.transform.rotation = carLevelPos[0].rotation; Debug.Log("First town"); } //Следы Skidmarks skids = character.GetComponentInChildren <Skidmarks>(); skids.gameObject.SetActive(true); skids.transform.position = Vector3.zero; skids.transform.rotation = Quaternion.identity; carcameras.gameObject.SetActive(true); cameraGarage.SetActive(false); CameraTarget tractor = character.GetComponentInChildren <CameraTarget>(); //Находим грузовик, на который будет нацелена камера if (tractor != null) { carcameras.target = tractor.transform; foreach (var butt in buttonsAddTrailer) { butt.TruckCar = tractor.transform; } AxisCarController aCC = tractor.GetComponent <AxisCarController>(); aCC.On = true; steer.axisCarController = aCC; buttonRulRight.axisCarController = aCC; buttonRulLeft.axisCarController = aCC; buttonBrake.axisCarController = aCC; buttonNitro.axisCarController = aCC; strelki.drivetrain = tractor.GetComponent <Drivetrain>(); map.Truck = tractor.transform; if (raceStart != null) //Если заходили в гагаж и меню станции { StartCoroutine(ShowStationMenu(gamePanel.animation.clip.length)); //!!! Должно быть не gamePanel, a Upgrade Panel aCC.InStation = true; Debug.LogWarning("Continue: raceStart != null"); } else//При первом запуске или перезапуск из гонки активируем Game Menu { aCC.InStation = false; StartCoroutine(ShowGameMenu(gamePanel.animation.clip.length)); Debug.LogWarning("Continue: raceStart == null"); } } gamePanel.enabled = true; cameraMap.SetActive(true); gragePanel.enabled = false; infoPanel.enabled = false; upgradePanel.enabled = false; }
public static GameObject CreateNewCar() { GameObject unityCarObj = new GameObject("UnityCar"); if (unityCarObj.rigidbody == null) { mrigidbody = unityCarObj.AddComponent <Rigidbody>() as Rigidbody; mrigidbody.mass = 1000; mrigidbody.angularDrag = 0; mrigidbody.interpolation = RigidbodyInterpolation.Interpolate; } else { mrigidbody = unityCarObj.GetComponent <Rigidbody>(); } if (unityCarObj.GetComponent <CarDynamics>() == null) { carDynamics = unityCarObj.AddComponent <CarDynamics>() as CarDynamics; } else { carDynamics = unityCarObj.GetComponent <CarDynamics>(); } centerOfMassObject = new GameObject("COG"); centerOfMassObject.transform.parent = unityCarObj.transform; centerOfMassObject.transform.localPosition = Vector3.zero; centerOfMassObject.transform.localRotation = Quaternion.identity; carDynamics.centerOfMass = centerOfMassObject.transform; if (unityCarObj.GetComponent <Drivetrain>() == null) { drivetrain = unityCarObj.AddComponent <Drivetrain>() as Drivetrain; } else { drivetrain = unityCarObj.GetComponent <Drivetrain>(); } if (unityCarObj.GetComponent <AxisCarController>() == null) { axisCarController = unityCarObj.AddComponent <AxisCarController>() as AxisCarController; } else { axisCarController = unityCarObj.GetComponent <AxisCarController>(); } /* * if (unityCarObj.GetComponent<SoundController>()==null) * soundController=unityCarObj.AddComponent<SoundController>() as SoundController; * else * soundController=unityCarObj.GetComponent<SoundController>(); * * soundController.enabled=false; */ if (unityCarObj.GetComponent <Axles>() == null) { axles = unityCarObj.AddComponent <Axles>() as Axles; } else { axles = unityCarObj.GetComponent <Axles>(); } // to avoid car assigned to default layer unityCarObj.layer = 1; if (unityCarObj.transform.Find("Body") == null) { bodyDown = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyDown.name = "Body"; Object.DestroyImmediate(bodyDown.collider); bodyDown.transform.parent = unityCarObj.transform; bodyDown.transform.localPosition = Vector3.zero; bodyDown.transform.localRotation = Quaternion.identity; bodyDown.transform.localScale = new Vector3(1.5f, 0.5f, 4); bodyUp = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyUp.name = "Body"; Object.DestroyImmediate(bodyUp.collider); bodyUp.transform.parent = unityCarObj.transform; bodyUp.transform.localRotation = Quaternion.identity; bodyUp.transform.localScale = new Vector3(bodyDown.transform.localScale.x, bodyDown.transform.localScale.y * 0.666f, bodyDown.transform.localScale.z / 2); bodyUp.transform.localPosition = new Vector3(0, bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y - bodyUp.transform.localScale.y) / 2, 0); } else { bodyDown = unityCarObj.transform.Find("Body").gameObject; } if (unityCarObj.transform.Find("Collider") == null) { mcollider = new GameObject("ColliderDown"); mcollider.transform.parent = unityCarObj.transform; mcollider.transform.localPosition = Vector3.zero; mcollider.transform.localRotation = Quaternion.identity; boxColliderDown = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider; boxColliderDown.transform.localScale = new Vector3(1.5f, 0.5f, 4); mcollider = new GameObject("ColliderUp"); mcollider.transform.parent = unityCarObj.transform; mcollider.transform.localRotation = Quaternion.identity; boxColliderUp = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider; boxColliderUp.transform.localScale = new Vector3(boxColliderDown.transform.localScale.x, boxColliderDown.transform.localScale.y * 0.666f, boxColliderDown.transform.localScale.z / 2); boxColliderUp.transform.localPosition = new Vector3(0, boxColliderDown.transform.localScale.y - (boxColliderDown.transform.localScale.y - boxColliderUp.transform.localScale.y) / 2, 0); } else { mcollider = unityCarObj.transform.Find("Collider").gameObject; boxColliderDown = mcollider.gameObject.GetComponent <BoxCollider>(); } if (unityCarObj.transform.Find("wheelFL") == null) { wheelFL = new GameObject("wheelFL"); wheelFL.transform.parent = unityCarObj.transform; wheel = wheelFL.gameObject.AddComponent <Wheel>() as Wheel; wheelFL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8); wheelFL.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.FRONT_LEFT; axles.frontAxle.leftWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelFL"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelFL.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelFL = unityCarObj.transform.Find("wheelFL").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelFL.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelFR") == null) { wheelFR = new GameObject("wheelFR"); wheelFR.transform.parent = unityCarObj.transform; wheel = wheelFR.gameObject.AddComponent <Wheel>() as Wheel; wheelFR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8); wheelFR.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.FRONT_RIGHT; axles.frontAxle.rightWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelFR"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelFR.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelFR = unityCarObj.transform.Find("wheelFR").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelFR.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelRL") == null) { wheelRL = new GameObject("wheelRL"); wheelRL.transform.parent = unityCarObj.transform; wheel = wheelRL.gameObject.AddComponent <Wheel>() as Wheel; wheelRL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8)); wheelRL.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.REAR_LEFT; axles.rearAxle.leftWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelRL"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelRL.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelRL = unityCarObj.transform.Find("wheelRL").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelRL.gameObject.layer = LayerMask.NameToLayer("Wheel"); } if (unityCarObj.transform.Find("wheelRR") == null) { wheelRR = new GameObject("wheelRR"); wheelRR.transform.parent = unityCarObj.transform; wheel = wheelRR.gameObject.AddComponent <Wheel>() as Wheel; wheelRR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8)); wheelRR.transform.localRotation = Quaternion.identity; wheel.showForces = false; wheel.wheelPos = WheelPos.REAR_RIGHT; axles.rearAxle.rightWheel = wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name = "modelRR"; Object.DestroyImmediate(model.collider); model.transform.parent = wheelRR.transform; model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; model.transform.localScale = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2); wheel.model = model; } else { wheelRR = unityCarObj.transform.Find("wheelRR").gameObject; } if (LayerMask.NameToLayer("Wheel") != -1) { wheelRR.gameObject.layer = LayerMask.NameToLayer("Wheel"); } axles.frontAxle.maxSteeringAngle = 33; axles.frontAxle.handbrakeFrictionTorque = 0; axles.rearAxle.maxSteeringAngle = 0; axles.rearAxle.handbrakeFrictionTorque = 1000; axles.frontAxle.tires = CarDynamics.Tires.competition_front; axles.rearAxle.tires = CarDynamics.Tires.competition_rear; axles.SetWheels(); /* dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard")); * if (dashBoard ){ * dashBoard.transform.parent=unityCarObj.transform; * dashBoard.transform.localPosition=Vector3.zero; * dashBoard.transform.localRotation=Quaternion.identity; * } */ // These are to avoid warning about "assigned but never used" drivetrain.enabled = true; axisCarController.enabled = true; return(unityCarObj); }
public void SetController(string strcontroller) { axisCarController = GetComponent <AxisCarController>(); // to make this function works with SaveSetup() mouseCarcontroller = GetComponent <MouseCarController>(); // to make this function works with SaveSetup() mobileCarController = GetComponent <MobileCarController>(); // to make this function works with SaveSetup() if (strcontroller == Controller.axis.ToString()) { if (axisCarController == null) { axisCarController = transform.gameObject.AddComponent <AxisCarController>(); } axisCarController.enabled = true; carController = axisCarController; if (drivetrain != null) { drivetrain.carController = axisCarController; } if (brakeLights != null) { brakeLights.carController = axisCarController; } if (dashBoard != null) { dashBoard.carController = axisCarController; } if (steeringWheel != null) { steeringWheel.carController = axisCarController; } if (soundController != null) { soundController.carController = axisCarController; } if (mouseCarcontroller != null) { mouseCarcontroller.enabled = false; } if (mobileCarController != null) { mobileCarController.enabled = false; } controller = Controller.axis; } else if (strcontroller == Controller.mouse.ToString()) { if (mouseCarcontroller == null) { mouseCarcontroller = transform.gameObject.AddComponent <MouseCarController>(); } mouseCarcontroller.enabled = true; mouseCarcontroller.smoothInput = false; carController = mouseCarcontroller; if (drivetrain != null) { drivetrain.carController = mouseCarcontroller; } if (brakeLights != null) { brakeLights.carController = mouseCarcontroller; } if (dashBoard != null) { dashBoard.carController = mouseCarcontroller; } if (steeringWheel != null) { steeringWheel.carController = mouseCarcontroller; } if (soundController != null) { soundController.carController = mouseCarcontroller; } if (axisCarController != null) { axisCarController.enabled = false; } if (mobileCarController != null) { mobileCarController.enabled = false; } controller = Controller.mouse; } else if (strcontroller == Controller.mobile.ToString()) { if (mobileCarController == null) { mobileCarController = transform.gameObject.AddComponent <MobileCarController>(); } mobileCarController.enabled = true; carController = mobileCarController; if (drivetrain != null) { drivetrain.carController = mobileCarController; } if (brakeLights != null) { brakeLights.carController = mobileCarController; } if (dashBoard != null) { dashBoard.carController = mobileCarController; } if (steeringWheel != null) { steeringWheel.carController = mobileCarController; } if (soundController != null) { soundController.carController = mobileCarController; } if (axisCarController != null) { axisCarController.enabled = false; } if (mouseCarcontroller != null) { mouseCarcontroller.enabled = false; } controller = Controller.mobile; } else if (strcontroller == Controller.external.ToString()) { if (mouseCarcontroller != null) { mouseCarcontroller.throttle = drivetrain.throttle = 0; mouseCarcontroller.enabled = false; } if (axisCarController != null) { axisCarController.throttle = drivetrain.throttle = 0; axisCarController.enabled = false; } if (mobileCarController != null) { mobileCarController.throttle = drivetrain.throttle = 0; mobileCarController.enabled = false; } controller = Controller.external; } }
//[MenuItem("GameObject/Create Other/UnityCar")] public static GameObject CreateNewCar(){ Debug.LogWarning("Create new car"); GameObject unityCarObj=new GameObject("UnityCar"); if (unityCarObj.rigidbody==null){ mrigidbody=unityCarObj.AddComponent<Rigidbody>() as Rigidbody; mrigidbody.mass=1000; mrigidbody.angularDrag=0; mrigidbody.interpolation=RigidbodyInterpolation.Interpolate; } else mrigidbody=unityCarObj.GetComponent<Rigidbody>(); if (unityCarObj.GetComponent<CarDynamics>()==null) carDynamics=unityCarObj.AddComponent<CarDynamics>() as CarDynamics; else carDynamics=unityCarObj.GetComponent<CarDynamics>(); centerOfMassObject=new GameObject("COG"); centerOfMassObject.transform.parent=unityCarObj.transform; centerOfMassObject.transform.localPosition=Vector3.zero; centerOfMassObject.transform.localRotation=Quaternion.identity; carDynamics.centerOfMass=centerOfMassObject.transform; if (unityCarObj.GetComponent<Drivetrain>()==null) drivetrain =unityCarObj.AddComponent<Drivetrain>() as Drivetrain; else drivetrain=unityCarObj.GetComponent<Drivetrain>(); if (unityCarObj.GetComponent<AxisCarController>()==null) axisCarController=unityCarObj.AddComponent<AxisCarController>() as AxisCarController; else axisCarController=unityCarObj.GetComponent<AxisCarController>(); /* if (unityCarObj.GetComponent<SoundController>()==null) soundController=unityCarObj.AddComponent<SoundController>() as SoundController; else soundController=unityCarObj.GetComponent<SoundController>(); soundController.enabled=false; */ if (unityCarObj.GetComponent<Axles>()==null) axles =unityCarObj.AddComponent<Axles>() as Axles; else axles =unityCarObj.GetComponent<Axles>(); // to avoid car assigned to default layer unityCarObj.layer=1; if (unityCarObj.transform.Find("Body")==null){ bodyDown = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyDown.name="Body"; Object.DestroyImmediate(bodyDown.collider); bodyDown.transform.parent=unityCarObj.transform; bodyDown.transform.localPosition=Vector3.zero; bodyDown.transform.localRotation=Quaternion.identity; bodyDown.transform.localScale=new Vector3(1.5f,0.5f,4); bodyUp = GameObject.CreatePrimitive(PrimitiveType.Cube); bodyUp.name="Body"; Object.DestroyImmediate(bodyUp.collider); bodyUp.transform.parent=unityCarObj.transform; bodyUp.transform.localRotation=Quaternion.identity; bodyUp.transform.localScale=new Vector3(bodyDown.transform.localScale.x,bodyDown.transform.localScale.y*0.666f,bodyDown.transform.localScale.z/2); bodyUp.transform.localPosition=new Vector3(0,bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y-bodyUp.transform.localScale.y)/2,0); } else{ bodyDown=unityCarObj.transform.Find("Body").gameObject; } if (unityCarObj.transform.Find("Collider")==null){ mcollider= new GameObject("ColliderDown"); mcollider.transform.parent=unityCarObj.transform; mcollider.transform.localPosition=Vector3.zero; mcollider.transform.localRotation=Quaternion.identity; boxColliderDown = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider; boxColliderDown.transform.localScale=new Vector3(1.5f,0.5f,4); mcollider= new GameObject("ColliderUp"); mcollider.transform.parent=unityCarObj.transform; mcollider.transform.localRotation=Quaternion.identity; boxColliderUp = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider; boxColliderUp.transform.localScale=new Vector3(boxColliderDown.transform.localScale.x,boxColliderDown.transform.localScale.y*0.666f,boxColliderDown.transform.localScale.z/2); boxColliderUp.transform.localPosition=new Vector3(0,boxColliderDown.transform.localScale.y-(boxColliderDown.transform.localScale.y-boxColliderUp.transform.localScale.y)/2,0); } else{ mcollider=unityCarObj.transform.Find("Collider").gameObject; boxColliderDown = mcollider.gameObject.GetComponent<BoxCollider>(); } if (unityCarObj.transform.Find("wheelFL")==null){ wheelFL = new GameObject("wheelFL"); wheelFL.transform.parent=unityCarObj.transform; wheel = wheelFL.gameObject.AddComponent<Wheel>() as Wheel; wheelFL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8); wheelFL.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.FRONT_LEFT; axles.frontAxle.leftWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelFL"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelFL.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelFL=unityCarObj.transform.Find("wheelFL").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelFL.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelFR")==null){ wheelFR = new GameObject("wheelFR"); wheelFR.transform.parent=unityCarObj.transform; wheel = wheelFR.gameObject.AddComponent<Wheel>() as Wheel; wheelFR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8); wheelFR.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.FRONT_RIGHT; axles.frontAxle.rightWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelFR"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelFR.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelFR=unityCarObj.transform.Find("wheelFR").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelFR.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelRL")==null){ wheelRL = new GameObject("wheelRL"); wheelRL.transform.parent=unityCarObj.transform; wheel = wheelRL.gameObject.AddComponent<Wheel>() as Wheel; wheelRL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8)); wheelRL.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.REAR_LEFT; axles.rearAxle.leftWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelRL"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelRL.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelRL=unityCarObj.transform.Find("wheelRL").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelRL.gameObject.layer=LayerMask.NameToLayer("Wheel"); if (unityCarObj.transform.Find("wheelRR")==null){ wheelRR = new GameObject("wheelRR"); wheelRR.transform.parent=unityCarObj.transform; wheel = wheelRR.gameObject.AddComponent<Wheel>() as Wheel; wheelRR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8)); wheelRR.transform.localRotation=Quaternion.identity; wheel.showForces=false; wheel.wheelPos=WheelPos.REAR_RIGHT; axles.rearAxle.rightWheel=wheel; model = GameObject.CreatePrimitive(PrimitiveType.Sphere); model.name="modelRR"; Object.DestroyImmediate(model.collider); model.transform.parent=wheelRR.transform; model.transform.localPosition=Vector3.zero; model.transform.localRotation=Quaternion.identity; model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2); wheel.model=model; } else{ wheelRR=unityCarObj.transform.Find("wheelRR").gameObject; } if (LayerMask.NameToLayer("Wheel")!=-1) wheelRR.gameObject.layer=LayerMask.NameToLayer("Wheel"); axles.frontAxle.maxSteeringAngle=33; axles.frontAxle.handbrakeFrictionTorque=0; axles.rearAxle.maxSteeringAngle=0; axles.rearAxle.handbrakeFrictionTorque=1000; axles.frontAxle.tires=CarDynamics.Tires.competition_front; axles.rearAxle.tires=CarDynamics.Tires.competition_rear; axles.SetWheels(); /* dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard")); if (dashBoard ){ dashBoard.transform.parent=unityCarObj.transform; dashBoard.transform.localPosition=Vector3.zero; dashBoard.transform.localRotation=Quaternion.identity; } */ // These are to avoid warning about "assigned but never used" drivetrain.enabled=true; axisCarController.enabled=true; return unityCarObj; }
private void OnTriggerEnter(Collider other) { if (other.gameObject.name.Substring(0, 2) == "TE") { if (activ)//finish { bool first = true;//Чтобы один и тот же грузовик не въехал 2 раза на финиш foreach (var nam in enemyNames) { if (other.gameObject.name == nam) first = false; } if (first) { enemyNames[prize - 1] = other.gameObject.name; prize += 1; } } } if (other.gameObject.name == "Traktor")//+ при переходе из гаража { PlayerPrefs.SetInt("StartCarPos", id); Debug.LogWarning("Tractor collider Enter"); if (other.GetComponent<CharacterJoint>() == null) { selectCarController.raceStart = this; truckPos.position = other.transform.position; MapCamera.SetActive(false); SetPanelState(true); axisCarController = other.gameObject.GetComponent<AxisCarController>(); axisCarController.InStation = true; gamePanel.alpha = 0; gamePanel.enabled = false; StartCoroutine(ShowStationMenu(finishPanel.animation.clip.length)); UIButton[] enableButtons = stationPanel.GetComponentsInChildren<UIButton>(); foreach (var eb in enableButtons) { eb.isEnabled = true; } } else { if (activ)//finish { if (other.gameObject.GetComponent<CharacterJoint>() != null) { selectCarController.raceStart = this; truckPos.position = other.transform.position; MapCamera.SetActive(false); SetPanelState(true); axisCarController = other.gameObject.GetComponent<AxisCarController>(); axisCarController.InStation = true; finishPanel.transform.position = Vector3.zero; finishPanel.enabled = true; gamePanel.alpha = 0; gamePanel.enabled = false; price = (int)(price*other.gameObject.GetComponent<BlowController>().Condition/100); if (prize == 1) { resultLabel.text = "1-st"; buttonAddTrailer.Medal = 0; } if (prize == 2) { resultLabel.text = "2-nd"; price = (int)(price*0.7f); buttonAddTrailer.Medal = Mathf.Min(1, buttonAddTrailer.Medal); } if (prize == 3) { resultLabel.text = "3-rd"; price = (int)(price * 0.6f); buttonAddTrailer.Medal = Mathf.Min(2, buttonAddTrailer.Medal); } if (prize == 4) { resultLabel.text = "4-th"; price = (int)(price * 0.5f); } if (prize == 5) { resultLabel.text = "5-th"; price = (int)(price * 0.4f); } addGoldLabel.text = price.ToString("f0"); buttonOk.GetComponent<UIButton>().isEnabled = true; StartCoroutine(AddGold(1)); prize = 1; for (int i = 0; i < enemyNames.Length; i++) { enemyNames[i] = ""; } baggageLabel.bonusPosCtrl.DeleteBonuses(); BlowController blowController = other.gameObject.GetComponent<BlowController>(); blowController.DestroyBoxes(); hasMoneyLabel.text = blowController.HasMoney.ToString("f0"); StartCoroutine(AddGoldForMoney(blowController.HasMoney, 2.5f)); blowController.HasMoney = 0; } } } } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.name.Substring(0, 2) == "TE") { if (activ) //finish { bool first = true; //Чтобы один и тот же грузовик не въехал 2 раза на финиш foreach (var nam in enemyNames) { if (other.gameObject.name == nam) { first = false; } } if (first) { enemyNames[prize - 1] = other.gameObject.name; prize += 1; } } } if (other.gameObject.name == "Traktor")//+ при переходе из гаража { PlayerPrefs.SetInt("StartCarPos", id); Debug.LogWarning("Tractor collider Enter"); if (other.GetComponent <CharacterJoint>() == null) { selectCarController.raceStart = this; truckPos.position = other.transform.position; MapCamera.SetActive(false); SetPanelState(true); axisCarController = other.gameObject.GetComponent <AxisCarController>(); axisCarController.InStation = true; gamePanel.alpha = 0; gamePanel.enabled = false; StartCoroutine(ShowStationMenu(finishPanel.animation.clip.length)); UIButton[] enableButtons = stationPanel.GetComponentsInChildren <UIButton>(); foreach (var eb in enableButtons) { eb.isEnabled = true; } } else { if (activ)//finish { if (other.gameObject.GetComponent <CharacterJoint>() != null) { selectCarController.raceStart = this; truckPos.position = other.transform.position; MapCamera.SetActive(false); SetPanelState(true); axisCarController = other.gameObject.GetComponent <AxisCarController>(); axisCarController.InStation = true; finishPanel.transform.position = Vector3.zero; finishPanel.enabled = true; gamePanel.alpha = 0; gamePanel.enabled = false; price = (int)(price * other.gameObject.GetComponent <BlowController>().Condition / 100); if (prize == 1) { resultLabel.text = "1-st"; buttonAddTrailer.Medal = 0; } if (prize == 2) { resultLabel.text = "2-nd"; price = (int)(price * 0.7f); buttonAddTrailer.Medal = Mathf.Min(1, buttonAddTrailer.Medal); } if (prize == 3) { resultLabel.text = "3-rd"; price = (int)(price * 0.6f); buttonAddTrailer.Medal = Mathf.Min(2, buttonAddTrailer.Medal); } if (prize == 4) { resultLabel.text = "4-th"; price = (int)(price * 0.5f); } if (prize == 5) { resultLabel.text = "5-th"; price = (int)(price * 0.4f); } addGoldLabel.text = price.ToString("f0"); buttonOk.GetComponent <UIButton>().isEnabled = true; StartCoroutine(AddGold(1)); prize = 1; for (int i = 0; i < enemyNames.Length; i++) { enemyNames[i] = ""; } baggageLabel.bonusPosCtrl.DeleteBonuses(); BlowController blowController = other.gameObject.GetComponent <BlowController>(); blowController.DestroyBoxes(); hasMoneyLabel.text = blowController.HasMoney.ToString("f0"); StartCoroutine(AddGoldForMoney(blowController.HasMoney, 2.5f)); blowController.HasMoney = 0; } } } } }
void Start(){ myTransform=transform; trs = myTransform.parent; while (trs != null && trs.rigidbody == null) trs = trs.parent; if (trs != null) body = trs.rigidbody; trs = myTransform.parent; while (trs.GetComponent<PhysicMaterials>() == null) {if (trs.parent) trs = trs.parent; else break;} physicMaterials = trs.GetComponent<PhysicMaterials>(); trs = myTransform.parent; while (trs.GetComponent<CarDynamics>() == null) trs = trs.parent; cardynamics = trs.GetComponent<CarDynamics>(); drivetrain = trs.GetComponent<Drivetrain>(); axles = trs.GetComponent<Axles>(); if (drivetrain != null) axisCarController = drivetrain.GetComponent<AxisCarController>(); localScale=1/(trs.localScale.y*myTransform.localScale.y); layerMask=1<<trs.gameObject.layer | 1<<myTransform.gameObject.layer | 1 << 29 | 1 << 1 | 1 << 2;//LayerMask.NameToLayer("Wheel"); layerMask=~layerMask; radiusLoaded=radius; if (rimRadius==0) rimRadius=radius*0.735f; sidewallHeight=radius - rimRadius; if (mass<50*cardynamics.invFixedTimeStepScalar) mass=50*cardynamics.invFixedTimeStepScalar; if (rotationalInertia==0 || rotationalInertia<(mass/2)*radius*radius) rotationalInertia=(mass/2)*radius*radius; originalMass=mass; if (model==null) { model = new GameObject("temp_model"); model.transform.parent=transform; model.transform.localPosition=new Vector3(0,0,0); model.transform.localRotation=Quaternion.identity; Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" +trs.name+ ")"); } modelTransform=model.transform; if (caliperModel!=null) caliperModelTransform=caliperModel.transform; skidmarks = cardynamics.skidmarks; //if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter;//b if (skidmarks && enableSkidParticles) { skidSmoke = skidmarks.SmokePe; skidGrass = skidmarks.GrassPe; skidSand = skidmarks.SandPe; skidSnow = skidmarks.SnowPe; } radiusTrack = radius; radiusSnow = radius*0.6f;//b suspensionLineRenderer=gameObject.GetComponent<LineRenderer>(); if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>(); suspensionLineRenderer.material = new Material(Shader.Find("Diffuse")); suspensionLineRenderer.material.color = Color.yellow; suspensionLineRenderer.SetWidth(0.01f,0.1f); suspensionLineRenderer.useWorldSpace = false; suspensionLineRenderer.castShadows = false; camber*=1; // to avoid never assigned warning if (camber==0){ up = myTransform.up; } else{ camberRotation = Quaternion.AngleAxis(-camber,forwardNormal); up = camberRotation*myTransform.up; } SetTireStiffness(); }
void Awake(){ body=rigidbody; originalCenterOfMass=body.centerOfMass; myTransform=transform; drivetrain= GetComponent<Drivetrain>(); axisCarController = GetComponent <AxisCarController>(); mouseCarcontroller = GetComponent <MouseCarController>(); mobileCarController = GetComponent <MobileCarController>(); brakeLights=GetComponent <BrakeLights>(); dashBoard = myTransform.GetComponentInChildren <DashBoard>(); steeringWheel = transform.GetComponentInChildren <SteeringWheel>(); soundController=GetComponent<SoundController>(); SetController(controller.ToString()); axles=GetComponent<Axles>(); //frontWheels=axles.frontAxle.wheels; //rearWheels=axles.rearAxle.wheels; //otherWheels=axles.otherWheels; //axles.allWheels=axles.axles.allWheels; invAllWheelsLength=1f/axles.allWheels.Length; fixedTimeStepScalar=0.02f/Time.fixedDeltaTime; invFixedTimeStepScalar=1/fixedTimeStepScalar; }