// this method creates a new atom from the type of the preFab and checks the position to have a far enough distance from other atoms public void createAtom(Rigidbody preFab) { int preFabID = preFab.GetInstanceID(); if(preFabID == atomTouchGUI.copperPrefab.GetInstanceID()){ Copper.count++; atomTouchGUI.copperCount.GetComponent<Text>().text = "Cu: " + Copper.count; }else if(preFabID == atomTouchGUI.goldPrefab.GetInstanceID()){ Gold.count++; atomTouchGUI.goldCount.GetComponent<Text>().text = "Au: " + Gold.count; }else if(preFabID == atomTouchGUI.platinumPrefab.GetInstanceID()){ Platinum.count++; atomTouchGUI.platinumCount.GetComponent<Text>().text = "Pt: " + Platinum.count; } CreateEnvironment myEnvironment = CreateEnvironment.myEnvironment; Quaternion curRotation = Quaternion.Euler(0, 0, 0); preFab.gameObject.GetComponent<MeshRenderer>().enabled = SettingsControl.renderAtoms; Debug.Log ("Rendering Atoms"); Instantiate(preFab, myEnvironment.centerPos, curRotation); int i = Atom.AllAtoms.Count-1; Atom currAtom = Atom.AllAtoms[i]; currAtom.gameObject.name = currAtom.GetInstanceID().ToString(); //Debug.Log(currAtom.GetInstanceID()); currAtom.GetComponent<Rigidbody>().freezeRotation = true; currAtom.GetComponent<TrailRenderer>().enabled = SettingsControl.mySettings.trailsToggle.isOn; float realWidth = myEnvironment.width - 2.0f * myEnvironment.errorBuffer; float realHeight = myEnvironment.height - 2.0f * myEnvironment.errorBuffer; float realDepth = myEnvironment.depth - 2.0f * myEnvironment.errorBuffer; Vector3 centerPos = myEnvironment.centerPos; int tryNumber = 0; bool proximityFlag = false; while ((proximityFlag == false) && (tryNumber < 100)) { tryNumber ++; currAtom.position = new Vector3 (centerPos.x + (UnityEngine.Random.Range (-realWidth/2.0f, realWidth/2.0f)), centerPos.y + (UnityEngine.Random.Range (-realHeight/2.0f, realHeight/2.0f)), centerPos.z + (UnityEngine.Random.Range (-realDepth/2.0f, realDepth/2.0f))); proximityFlag = myEnvironment.checkProximity(currAtom); } currAtom.transform.position = currAtom.position; StartCoroutine(Blink(currAtom)); //kick it atomTouchGUI.AtomKick(i); Potential.myPotential.calculateVerletRadius (currAtom); if ((tryNumber == 100) && (proximityFlag == false)) { Atom.UnregisterAtom(currAtom); Destroy (currAtom.gameObject); Debug.Log ("No space for atoms!"); } }