private void OnCollisionEnter(Collision collider) { //print(collider.gameObject.tag); if (collider.gameObject.tag == "Calcium") { print("collided with calcium!"); Vector3 Rpos = gameObject.transform.position; Vector3 Opos = collider.transform.position; Redox otherP = collider.gameObject.GetComponent <Redox>(); //otherP stands for other particle GameObject NewObject1; GameObject NewObject2; //GameObject NewObject3; //spawn the new objects with the old coordinates but flipped //NewObject3 = Instantiate(otherP.ReactionPrefab, Opos, Quaternion.identity); NewObject1 = Instantiate(ReactionPrefab1, Rpos, Quaternion.identity); NewObject2 = Instantiate(ReactionPrefab2, Rpos, Quaternion.identity); Soundsource.Play(); if (otherP.GetComponent <LabelAssigner>().hasFlag == true) { NewObject1.GetComponent <LabelAssigner>().hasFlag = true; } //Move the old objects to oblivion gameObject.transform.position = new Vector3(1200, 1200, 1200); collider.gameObject.transform.position = new Vector3(-500, -500, 0); } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.GetComponent <Redox>() != null) { Redox otherP = collision.gameObject.GetComponent <Redox>(); //otherP stands for other particle if (otherP.isReducingAgent == true && isOxidizingAgent == true && isReacting == false) { StartCoroutine("ReactionDelay"); //temp = temperatureSlider.value; tempfactor = 5.1f / temperatureSlider.value; probability = Random.Range(0.0f, tempfactor); print(probability); if (probability < EP + otherP.EP) { //gets positions of both objects Vector3 Rpos = gameObject.transform.position; Vector3 Opos = otherP.transform.position; GameObject NewObject1; GameObject NewObject2; //spawn the new objects with the old coordinates but flipped NewObject1 = Instantiate(otherP.ReactionPrefab, Opos, Quaternion.identity); NewObject2 = Instantiate(ReactionPrefab, Rpos, Quaternion.identity); //Flag management if (otherP.GetComponent <LabelAssigner>().hasFlag == true) { NewObject2.GetComponent <LabelAssigner>().hasFlag = true; } else if (gameObject.GetComponent <LabelAssigner>().hasFlag == true) { NewObject2.GetComponent <LabelAssigner>().hasFlag = true; } //Destroy the old objects gameObject.name = "destroyed"; mainObject.gameObjects.Remove(gameObject); Destroy(otherP.gameObject); otherP.gameObject.name = "destroyed"; mainObject.gameObjects.Remove(otherP.gameObject); Destroy(gameObject); //Plays a sound Soundsource.Play(); //The need to rename the gameobject is so that it loses the [P] tag //The tag will automatically re-add the particle to the physics list //If an object is destroyed without being removed from the physics list, //all physics will stop until it is resolved } //ELSE, PLAY A "DENIED SOUND" SO THAT NON-PRODUCTIVE COLLISIONS CAN BE HEARD! } } }