public virtual IEnumerator ElectronToProton() { Transform target = Nucleus.recentParticle; Vector3 pos = Vector3.right * this.orbitals.shells[this.orbitals.outerShell].radius; GameObject particleObj = UnityEngine.Object.Instantiate(this.particlePrefab, pos, Quaternion.identity); particleObj.GetComponent <Renderer>().material.mainTexture = (Texture2D)Resources.Load("Electron_TIF"); float time = 0.8f; CreatorParticle mover = (CreatorParticle)particleObj.GetComponent(typeof(CreatorParticle)); mover.lifetime = time; float startTime = Time.time; while (Time.time < (startTime + time)) { particleObj.transform.position = Vector3.Lerp(pos, target.position, (Time.time - startTime) / time); yield return(null); } target.GetComponent <Renderer>().material.mainTexture = (Texture2D)Resources.Load("Hydrogen_TIF"); target.localScale = target.localScale * 2.2f; }
public override void Drop(Draggable d) { float time = 0f; Draggable_Nucleon nuc = d as Draggable_Nucleon; Vector3 pos = DragNDrop.ScreenToWorld(Input.mousePosition) + Vector3.forward; Vector3 outDir = new Vector3(pos.x, pos.y, 0).normalized; GameObject particleObj = UnityEngine.Object.Instantiate(this.particlePrefab, pos, Quaternion.identity); CreatorParticle mover = (CreatorParticle)particleObj.GetComponent(typeof(CreatorParticle)); string resourceName = nuc.type == PType.E ? "Electron_TIF" : (nuc.type == PType.P ? "Proton_TIF" : "Neutron_TIF"); particleObj.GetComponent <Renderer>().material.mainTexture = (Texture2D)Resources.Load(resourceName); if (this.mouseOver == 0) { if (nuc.type == PType.E) { if ((UserAtom.p >= UserAtom.e) && (AtomChart.elements[UserAtom.p - 1].grabElectron || (UserAtom.e < UserAtom.p))) { float speed = 3f; Vector3 targetPos = Vector3.right * this.orbitals.shells[this.orbitals.outerShell].radius; speed = Mathf.Clamp(speed * (targetPos - pos).magnitude, 3, 10); time = (pos - targetPos).magnitude / speed; mover.velocity = (targetPos - pos).normalized * speed; mover.lifetime = time; this.StartCoroutine(this.AddToOrbitalsRoutine(time)); } else { mover.velocity = outDir * (UserAtom.p < UserAtom.e ? 4 : 1); mover.lifetime = 10; } } else { if (nuc.type == PType.N) { mover.velocity = outDir; mover.lifetime = 10; } else { float ratio = Mathf.Min(pos.magnitude / this.orbitals.shells[this.orbitals.outerShell].radius, 1); mover.velocity = outDir * Mathf.Lerp(8, 1, ratio); mover.lifetime = 10; } } } else { // mouseOver == 1 if (nuc.type == PType.E) { mover.velocity = outDir * 8; mover.lifetime = 3; } else { mover.velocity = outDir * -4; time = 0.2f; mover.lifetime = time; this.StartCoroutine(this.AddToNucleusRoutine(time, nuc.type)); } } }