public void ChangeTerrainType(GameObject other) //chose gameobject rather than NewCarController to keep the OnTrigger intact. { NewCarController cCont = other.GetComponent <NewCarController>(); //TODO if wheels Offroad, do other stats. switch (terrainTypePicker) { case TerrainTypePicker.Grass: cCont.carStats.terrainMultiplier = 0.5f; break; case TerrainTypePicker.Mud: cCont.carStats.terrainMultiplier = 0.2f; break; case TerrainTypePicker.Tarmac: cCont.carStats.terrainMultiplier = 1f; break; case TerrainTypePicker.BoostSpeed: cCont.carStats.terrainMultiplier = 3f; break; case TerrainTypePicker.BoostSlow: cCont.carStats.terrainMultiplier = 0.6f; break; } cCont.TerrainType = terrainTypePicker; }
private void Awake() { // get the car controller m_Car = GetComponent <NewCarController>(); rb = GetComponent <Rigidbody>(); forkliftAudio = GetComponent <AudioSource>(); reverseMode = false; toucpadControl = false; charController = GetComponent <VRCharController>(); }
private void Awake() { // get the car controller reference m_CarController = GetComponent <NewCarController>(); // give the random perlin a random value m_RandomPerlin = Random.value * 100; m_Rigidbody = GetComponent <Rigidbody>(); }
private void OnTriggerEnter(Collider collider) { NewCarController cc = collider.GetComponent <NewCarController>(); cc.PickUp(pickUpType, gameObject, this); if (cc.PickUpDestroy(pickUpType)) { Destroy(this.gameObject); } }
private void Awake() { if (vehicleController == null) { vehicleController = GetComponent <NewCarController>(); } if (agentRigidbody == null) { agentRigidbody = GetComponent <Rigidbody>(); } if (depth == null) { depth = GetComponent <CameraSensorComponent>(); } if (target == null) { target = transform.parent.Find("Target"); } agentStartPosition = transform.position; agentStartRotation = transform.rotation; if (!training) { return; } if (env == null) { env = GetComponentInParent <RandomEnvironment>(); } if (objectSpawner == null) { objectSpawner = transform.parent.Find("Object Spawner").GetComponent <ObjectSpawner>(); } transform.parent = env.transform; transform.localPosition = Vector3.zero; maxDistanceFromStart = Mathf.Max( env.length / 2, env.width / 2 ) * 1.25f; maxDistanceFromStartSq = maxDistanceFromStart * maxDistanceFromStart; }
private void Awake() { // get the car controller m_Car = GetComponent <NewCarController>(); }
// Start is called before the first frame update void Start() { newCarController = FindObjectOfType <NewCarController>(); }
private void Start() { Application.targetFrameRate = 60; newCarController = FindObjectOfType <NewCarController>(); }
private GameObject Construct(int player) { if (!File.Exists(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt")) { Debug.Log("No Save-File could be found! Are you sure you saved something?"); //TODO show on screen. return(null); } //Get JSON string json = File.ReadAllText(Application.dataPath + @"\PlacedBlocksCatergories" + player + ".txt"); Dictionary <string, BlockSave[]> stringDict = JsonConvert.DeserializeObject <Dictionary <string, BlockSave[]> >(json); Dictionary <CarComponents.Type, BlockSave[]> enumDict = new Dictionary <CarComponents.Type, BlockSave[]>(); List <BlockSave> list = new List <BlockSave>(); foreach (string enumName in stringDict.Keys) { CarComponents.Type type = (CarComponents.Type)Enum.Parse(typeof(CarComponents.Type), enumName, true); enumDict.Add(type, stringDict[enumName]); list.AddRange(stringDict[enumName]); } GameObject car = new GameObject("Car P" + player); //1. Static meshes (hull) GameObject hull = new GameObject("Hull"); hull.transform.SetParent(car.transform); //2. Wheel Visuals (renderers) GameObject wheelRenderers = new GameObject("Wheels"); wheelRenderers.transform.SetParent(car.transform); CarStats carStats = new CarStats(); //Fill the containers foreach (BlockSave blockSave in list) { GameObject prefab = ReturnBlockToPlace(blockSave.name); CarComponent component = (CarComponent)BuildController.GetComponent(blockSave.name); GameObject block; switch (component.type) { case CarComponents.Type.Wheel: block = Instantiate(prefab, StringToVector3(blockSave.position), StringToQuaternion(blockSave.rotation), wheelRenderers.transform); break; default: block = Instantiate(prefab, StringToVector3(blockSave.position), StringToQuaternion(blockSave.rotation), hull.transform); break; } carStats = ModifyCarStats(component, carStats); } ///Setup rigidbody + collider //Combine all meshes into one MeshFilter[] meshFilters = hull.GetComponentsInChildren <MeshFilter>(); CombineInstance[] combine = new CombineInstance[meshFilters.Length]; for (int i = 0; i < meshFilters.Length; i++) { combine[i].mesh = meshFilters[i].sharedMesh; combine[i].transform = meshFilters[i].transform.localToWorldMatrix; if (meshFilters[i].GetComponent <MeshCollider>()) { meshFilters[i].GetComponent <MeshCollider>().enabled = false; } } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combine); MeshCollider combinedCollider = car.gameObject.AddComponent <MeshCollider>(); combinedCollider.sharedMesh = combinedMesh; combinedCollider.convex = true; Rigidbody carRb = car.AddComponent <Rigidbody>(); carRb.mass = 1500; //3. Wheel Colliders (colliders) List <WheelCollider> wheelColls = new List <WheelCollider>(); List <Transform> wheelCollsTs = new List <Transform>(); List <Transform> wheelTrans = new List <Transform>(); GameObject wheelColliders = Instantiate(wheelRenderers, wheelRenderers.transform.position, wheelRenderers.transform.rotation, car.transform); wheelColliders.name = "WheelCollliders"; //we need the lists to start with the two front wheels Transform front1col = null; Transform front2col = null; for (int i = 0; i < wheelColliders.transform.childCount; i++) { Transform child = wheelColliders.transform.GetChild(i); if (front1col == null) { front1col = child; } else { if (child.position.z > front1col.position.z) { front1col = child; } } } for (int i = 0; i < wheelColliders.transform.childCount; i++) { Transform child = wheelColliders.transform.GetChild(i); if (child != front1col) { if (front2col == null) { front2col = child; } else { if (child.position.z > front2col.position.z) { front2col = child; } } } } wheelCollsTs.Add(front1col); wheelCollsTs.Add(front2col); for (int child = 0; child < wheelColliders.transform.childCount; child++) { Transform wheel = wheelColliders.transform.GetChild(child); //Remove all renderers List <MeshRenderer> renderers = new List <MeshRenderer>(); renderers.AddRange(wheel.GetComponents <MeshRenderer>()); renderers.AddRange(wheel.GetComponentsInChildren <MeshRenderer>()); foreach (MeshRenderer renderer in renderers) { Destroy(renderer); } List <MeshFilter> filters = new List <MeshFilter>(); filters.AddRange(wheel.GetComponents <MeshFilter>()); filters.AddRange(wheel.GetComponentsInChildren <MeshFilter>()); foreach (MeshFilter filter in filters) { Destroy(filter); } //Remove all colliders List <Collider> colls = new List <Collider>(); colls.AddRange(wheel.GetComponents <Collider>()); colls.AddRange(wheel.GetComponentsInChildren <Collider>()); //Add Wheel Colliders WheelCollider wheelColl = wheel.gameObject.AddComponent <WheelCollider>(); wheelColl.mass = 10f; wheelColl.radius = 1f; wheelColl.wheelDampingRate = 1f; wheelColl.suspensionDistance = .08f; if (!wheelCollsTs.Contains(wheel)) { wheelCollsTs.Add(wheel); } foreach (Collider coll in colls) { Destroy(coll); } } foreach (Transform wheelColTs in wheelCollsTs) { wheelColls.Add(wheelColTs.GetComponent <WheelCollider>()); } //Clear components from the wheel renderers Transform front1ts = null; Transform front2ts = null; for (int i = 0; i < wheelRenderers.transform.childCount; i++) { Transform child = wheelRenderers.transform.GetChild(i); if (front1ts == null) { front1ts = child; } else { if (child.position.z > front1ts.position.z) { front1ts = child; } } } for (int i = 0; i < wheelRenderers.transform.childCount; i++) { Transform child = wheelRenderers.transform.GetChild(i); if (child != front1ts) { if (front2ts == null) { front2ts = child; } else { if (child.position.z > front2ts.position.z) { front2ts = child; } } } } wheelTrans.Add(front1ts); wheelTrans.Add(front2ts); GameObject[] wheelRender = new GameObject[wheelRenderers.transform.childCount]; for (int i = 0; i < wheelRenderers.transform.childCount; i++) { wheelRender[i] = wheelRenderers.transform.GetChild(i).gameObject; } foreach (GameObject wheel in wheelRender) { GameObject wheelParent = new GameObject("Wheelparent"); wheelParent.transform.SetParent(wheel.transform.parent); wheelParent.transform.position = wheel.transform.position; wheelParent.transform.rotation = wheel.transform.rotation; wheel.transform.SetParent(wheelParent.transform); if (!wheelTrans.Contains(wheel.transform)) { wheelTrans.Add(wheel.transform); } //Remove all colliders List <Collider> colls = new List <Collider>(); colls.AddRange(wheelParent.GetComponents <Collider>()); colls.AddRange(wheelParent.GetComponentsInChildren <Collider>()); foreach (Collider coll in colls) { Destroy(coll); } } NewCarController controller = car.AddComponent <NewCarController>(); controller.wheelColliders = wheelColls.ToArray(); controller.wheelTransforms = wheelTrans.ToArray(); controller.player = player; controller.particleSystems = car.GetComponentsInChildren <ParticleSystem>(); controller.rb = carRb; controller.carStats = carStats; if (player == 1) { car.transform.position = spawnPosP1; controller.spawnPos = spawnPosP1; } else { car.transform.position = spawnPosP2; controller.spawnPos = spawnPosP2; } SetLayerRecursively(car, 9); carRb.drag = .5f; carStats.terrainMultiplier = 1f; //carRb.angularDrag = .5f; return(car); }
// Start is called before the first frame update void Start() { m_Car = GetComponent <NewCarController>(); layerMask = ~layerMask; }
// Start is called before the first frame update void Start() { gm = GameObject.Find("GameManager").GetComponent <GameManager>(); macchina = GameObject.Find("CarParent").GetComponent <NewCarController>(); }
// Daha sonra metodları foreache çevir void Start() { forkController = GetComponent <ForkController>(); newCarController = GetComponent <NewCarController>(); newCarUserControl = GetComponent <NewCarUserControl>(); }