private void OnCollisionEnter(Collision collision) { CarFactorBehaviour shieldCheck = collision.gameObject.GetComponent <CarFactorBehaviour>(); if ((collision.gameObject.tag == "Player" && shieldCheck.shieldOn == false) || (collision.gameObject.tag == "Player 2" && shieldCheck.shieldOn == false) || (collision.gameObject.tag == "Player 3" && shieldCheck.shieldOn == false) || (collision.gameObject.tag == "Player4" && shieldCheck.shieldOn == false)) { //Meant to lower car's current speed by such collision.rigidbody.AddForce(-collision.rigidbody.velocity / 30); Destroy(gameObject); User.GetComponent <GameObject>().tag = "LockOn"; Tracking = false; } //If it hits anything that isn't the user of the item if (collision.gameObject != user) { Destroy(gameObject); User.GetComponent <GameObject>().tag = "LockOn"; Tracking = false; } if (collision.gameObject.tag == "Wall") { Destroy(gameObject); User.GetComponent <GameObject>().tag = "LockOn"; Tracking = false; } }
// Update is called once per frame void Update() { for (int i = 0; i < placement.Count; i++) { for (int j = 0; j < placement.Count; j++) { //This should reorder all the cars by placement CarFactorBehaviour iCFB = placement[i].GetComponent <CarFactorBehaviour>(); CarFactorBehaviour jCFB = placement[j].GetComponent <CarFactorBehaviour>(); if ((jCFB.WayPointPass > iCFB.WayPointPass) && j > i) { List <GameObject> temp = placement; temp[i] = placement[j]; temp[j] = placement[i]; placement = temp; } } } }