// Use this for initialization void Start() { myAI = GetComponent <AIController>(); bDestroyer = UnityEngine.Camera.main.GetComponentInChildren <BoundaryDestroyer>(); carUniqueID = carCounter++; currentGear = 0; rb = GetComponent <Rigidbody>(); exhausts = GetComponentsInChildren <ParticleSystem>(); if (rearLeftWheel == null) { rearLeftWheel = transform.GetChild(0).Find("Wheel").transform.Find("LeftRear").GetComponent <WheelController>(); } if (rearRightWheel == null) { rearRightWheel = transform.GetChild(0).Find("Wheel").transform.Find("RightRear").GetComponent <WheelController>(); } if (frontLeftWheel == null) { frontLeftWheel = transform.GetChild(0).Find("Wheel").transform.Find("LeftFront").GetComponent <WheelController>(); } if (frontRightWheel == null) { frontRightWheel = transform.GetChild(0).Find("Wheel").transform.Find("RightFront").GetComponent <WheelController>(); } // We set the boolean variables of the wheels rearLeftWheel.isRearWheel = true; rearRightWheel.isRearWheel = true; frontLeftWheel.isRearWheel = false; frontRightWheel.isRearWheel = false; // We obtain the position of the wheels to calculate the different weights frontRightPosition = frontRightWheel.transform.localPosition.z; rearRightPosition = rearRightWheel.transform.localPosition.z; // Text over the car with the player it is - now handled by sliders var txtMsh = transform.Find("Text").GetComponent <TextMesh>(); txtMsh.text = ""; switch (myPlayerData.getID()) { case 1: txtMsh.color = Color.blue; break; case 2: txtMsh.color = Color.red; break; case 3: txtMsh.color = Color.green; break; case 4: txtMsh.color = Color.yellow; break; } // We set the health slider to each player healthSlider = GameObject.Find("HealthSliderP" + (myPlayerData.getID()).ToString()).GetComponentInChildren <Slider>(); healthSlider2 = GameObject.Find("HealthSliderP" + (myPlayerData.getID()).ToString() + "2").GetComponentInChildren <Slider>(); // We try to set the background colour as well the same as appear in top of the car healthSlider.transform.GetChild(1).GetChild(0).GetComponent <Image>().color = txtMsh.color; healthSlider2.transform.GetChild(1).GetChild(0).GetComponent <Image>().color = txtMsh.color; sounds = GetComponents <AudioSource>(); noise1 = sounds[0]; noise2 = sounds[1]; // We set the initial health of the car+ currentHealth = startingHealth; if (myAI == null) { noise1.pitch = (rpm / 10000) + 0.7f; // formula to reach ideal pitch from rpm } else { noise1.mute = true; } // If this is a respawn, the set a different layer to prevent collision with other cars if (transform.position.z > 3.0f) { respawnInvTime = 3.0f; var col = transform.Find("Colliders"); col.gameObject.layer = LayerMask.NameToLayer("CarRespawningHitbox"); for (int i = 0; i < col.transform.childCount; i++) { col.GetChild(i).gameObject.layer = LayerMask.NameToLayer("CarRespawningHitbox"); } } }
// Use this for initialization void Start() { myAI = GetComponent<AIController>(); bDestroyer = UnityEngine.Camera.main.GetComponentInChildren<BoundaryDestroyer>(); carUniqueID = carCounter++; currentGear = 0; rb = GetComponent<Rigidbody>(); exhausts = GetComponentsInChildren<ParticleSystem>(); if (rearLeftWheel == null) rearLeftWheel = transform.GetChild(0).Find("Wheel").transform.Find("LeftRear").GetComponent<WheelController>(); if (rearRightWheel == null) rearRightWheel = transform.GetChild(0).Find("Wheel").transform.Find("RightRear").GetComponent<WheelController>(); if (frontLeftWheel == null) frontLeftWheel = transform.GetChild(0).Find("Wheel").transform.Find("LeftFront").GetComponent<WheelController>(); if (frontRightWheel == null) frontRightWheel = transform.GetChild(0).Find("Wheel").transform.Find("RightFront").GetComponent<WheelController>(); // We set the boolean variables of the wheels rearLeftWheel.isRearWheel = true; rearRightWheel.isRearWheel = true; frontLeftWheel.isRearWheel = false; frontRightWheel.isRearWheel = false; // We obtain the position of the wheels to calculate the different weights frontRightPosition = frontRightWheel.transform.localPosition.z; rearRightPosition = rearRightWheel.transform.localPosition.z; // Text over the car with the player it is - now handled by sliders var txtMsh = transform.Find("Text").GetComponent<TextMesh>(); txtMsh.text = ""; switch (myPlayerData.getID()) { case 1: txtMsh.color = Color.blue; break; case 2: txtMsh.color = Color.red; break; case 3: txtMsh.color = Color.green; break; case 4: txtMsh.color = Color.yellow; break; } // We set the health slider to each player healthSlider = GameObject.Find("HealthSliderP" + (myPlayerData.getID()).ToString()).GetComponentInChildren<Slider>(); healthSlider2 = GameObject.Find("HealthSliderP" + (myPlayerData.getID()).ToString() + "2").GetComponentInChildren<Slider>(); // We try to set the background colour as well the same as appear in top of the car healthSlider.transform.GetChild(1).GetChild(0).GetComponent<Image>().color = txtMsh.color; healthSlider2.transform.GetChild(1).GetChild(0).GetComponent<Image>().color = txtMsh.color; sounds = GetComponents<AudioSource>(); noise1 = sounds[0]; noise2 = sounds[1]; // We set the initial health of the car+ currentHealth = startingHealth; if (myAI == null) { noise1.pitch = (rpm / 10000) + 0.7f; // formula to reach ideal pitch from rpm } else { noise1.mute = true; } // If this is a respawn, the set a different layer to prevent collision with other cars if (transform.position.z > 3.0f) { respawnInvTime = 3.0f; var col = transform.Find("Colliders"); col.gameObject.layer = LayerMask.NameToLayer("CarRespawningHitbox"); for (int i = 0; i < col.transform.childCount; i++) { col.GetChild(i).gameObject.layer = LayerMask.NameToLayer("CarRespawningHitbox"); } } }