private void Update() { if (Player.lose == false) { player.gameObject.GetComponent <Rigidbody2D>().velocity -= player.gameObject.GetComponent <Rigidbody2D>().velocity; } if (SelectNowSphere.id == 1 && PlayerPrefs.GetString(Sphere1.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material; } else if (SelectNowSphere.id == 2 && PlayerPrefs.GetString(Sphere2.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material; } else if (SelectNowSphere.id == 3 && PlayerPrefs.GetString(Sphere3.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material; } else if (SelectNowSphere.id == 4 && PlayerPrefs.GetString(Sphere4.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material; } else if (SelectNowSphere.id == 5 && PlayerPrefs.GetString(Sphere5.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material; } }
void OnMouseUp() { transform.localScale = new Vector3(1f, 1f, 1f); if (id == 1 && PlayerPrefs.GetString(Sphere1.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material; } else if (id == 2 && PlayerPrefs.GetString(Sphere2.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material; } else if (id == 3 && PlayerPrefs.GetString(Sphere3.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material; } else if (id == 4 && PlayerPrefs.GetString(Sphere4.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material; } else if (id == 5 && PlayerPrefs.GetString(Sphere5.gameObject.name) == "Open") { mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material; } }
public void Reset() { V1 = 0f; V2 = 0f; Po1.x = x1i; Po2.x = x2i; Sphere1.GetComponent <Transform>().position = Po1; Sphere2.GetComponent <Transform>().position = Po2; }
// Start is called before the first frame update void Start() { Sphere1 = GameObject.Find("Sphere_A"); Sphere2 = GameObject.Find("Sphere_B"); Po1 = Sphere1.GetComponent <Transform>().position; Po2 = Sphere2.GetComponent <Transform>().position; R = 10f; x1i = Po1.x; x2i = Po2.x; V1 = 0; V2 = 0; }
void OnMouseUp() { BuySound.Play(); transform.localScale = new Vector3(1f, 1f, 1f); if (PlayerPrefs.GetInt("Coins") >= 40 && SelectNowSphere.id == 1) { PlayerPrefs.SetString(Sphere1.GetComponent <SelectSphere>().nowSphere, "Open"); mainSphere.GetComponent <MeshRenderer>().material = Sphere1.GetComponent <MeshRenderer>().material; PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 40); selectBtn.SetActive(true); gameObject.SetActive(false); } else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 2) { PlayerPrefs.SetString(Sphere2.GetComponent <SelectSphere>().nowSphere, "Open"); mainSphere.GetComponent <MeshRenderer>().material = Sphere2.GetComponent <MeshRenderer>().material; PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150); selectBtn.SetActive(true); gameObject.SetActive(false); } else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 3) { PlayerPrefs.SetString(Sphere3.GetComponent <SelectSphere>().nowSphere, "Open"); mainSphere.GetComponent <MeshRenderer>().material = Sphere3.GetComponent <MeshRenderer>().material; PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150); selectBtn.SetActive(true); gameObject.SetActive(false); } else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 4) { PlayerPrefs.SetString(Sphere4.GetComponent <SelectSphere>().nowSphere, "Open"); mainSphere.GetComponent <MeshRenderer>().material = Sphere4.GetComponent <MeshRenderer>().material; PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150); selectBtn.SetActive(true); gameObject.SetActive(false); } else if (PlayerPrefs.GetInt("Coins") >= 150 && SelectNowSphere.id == 5) { PlayerPrefs.SetString(Sphere5.GetComponent <SelectSphere>().nowSphere, "Open"); mainSphere.GetComponent <MeshRenderer>().material = Sphere5.GetComponent <MeshRenderer>().material; // PlayerPrefs.SetString("Now", Sphere5.GetComponent<SelectSphere>().nowSphere); PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") - 150); selectBtn.SetActive(true); gameObject.SetActive(false); } }
// Update is called once per frame void Update() { if (Mathf.Abs(Po1.x - Po2.x) <= (R)) { V1 = Vc1; V2 = Vc2; } Po1.x = Po1.x + Time.fixedDeltaTime * V1; Po2.x = Po2.x + Time.fixedDeltaTime * V2; Sphere1.GetComponent <Transform>().position = Po1; Sphere2.GetComponent <Transform>().position = Po2; }
void Update() { PosEsf1 = gameObject.GetComponent <Transform>().position; if (Input.GetKey(KeyCode.UpArrow) && (PosEsf1.z + Rad) < LimU) { if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.x - PosEsf2.x), 2) + Mathf.Pow((PosEsf1.z - PosEsf2.z), 2))) > (Rad2)) //si las esferas no se tocan { V1z = V1z + 1f; } else //si si se tocan { if (LimU >= (PosEsf2.z + Rad) && (PosEsf2.z > PosEsf1.z)) //revisar si no se tocan contra pared { V2z = (((1 + e) * M1) / (M1 + M2)) * V1z; PosEsf2.z = PosEsf2.z + Time.fixedDeltaTime * V2z; PosEsf1.z = PosEsf1.z + 1f; } if (PosEsf2.z < PosEsf1.z) { PosEsf1.z = PosEsf1.z + 1f; V1z = V1z + 1f; } } } if (Input.GetKey(KeyCode.DownArrow) && (PosEsf1.z - Rad) > LimD) { if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.x - PosEsf2.x), 2) + Mathf.Pow((PosEsf1.z - PosEsf2.z), 2))) > (Rad2)) { PosEsf1.z = PosEsf1.z - 1f; } else { if (LimD <= (PosEsf2.z - Rad) && (PosEsf2.z < PosEsf1.z)) { PosEsf2.z = PosEsf2.z - 1f; PosEsf1.z = PosEsf1.z - 1f; } if (PosEsf2.z > PosEsf1.z) { PosEsf1.z = PosEsf1.z - 1f; } } } if (Input.GetKey(KeyCode.RightArrow) && (PosEsf1.x + Rad) < LimR) { if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) > (Rad2)) { PosEsf1.x = PosEsf1.x + 0.05f; } else { if (LimR >= (PosEsf2.x + Rad) && (PosEsf2.x > PosEsf1.x)) { PosEsf2.x = PosEsf2.x + 0.05f; PosEsf1.x = PosEsf1.x + 0.05f; } if (PosEsf2.x < PosEsf1.x) { PosEsf1.x = PosEsf1.x + 0.05f; } } } if (Input.GetKey(KeyCode.LeftArrow) && (PosEsf1.x - Rad) > LimL) { if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) > (Rad2)) { PosEsf1.x = PosEsf1.x - 0.05f; } else { if (LimL <= (PosEsf2.x - Rad) && (PosEsf2.x < PosEsf1.x)) { PosEsf2.x = PosEsf2.x - 0.05f; PosEsf1.x = PosEsf1.x - 0.05f; } if (PosEsf2.x > PosEsf1.x) { PosEsf1.x = PosEsf1.x - 0.05f; } } } if (Input.GetKey(KeyCode.W)) { LimU = LimU + 0.05f; LimD = LimD + 0.05f; if (LimD >= (PosEsf1.z - Rad)) { PosEsf1.z = LimD + Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf2.z = PosEsf1.z + Rad2; } } if (LimD >= (PosEsf2.z - Rad)) { PosEsf2.z = LimD + Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf1.z = PosEsf2.z + Rad2; } } } if (Input.GetKey(KeyCode.S)) { LimU = LimU - 0.05f; LimD = LimD - 0.05f; if (LimU <= (PosEsf1.z + Rad)) { PosEsf1.z = LimU - Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf2.z = PosEsf1.z - Rad2; } } if (LimU <= (PosEsf2.z + Rad)) { PosEsf2.z = LimU - Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf1.z = PosEsf2.z - Rad2; } } } if (Input.GetKey(KeyCode.D)) { LimR = LimR + 0.05f; LimL = LimL + 0.05f; if (LimL >= (PosEsf1.x - Rad)) { PosEsf1.x = LimL + Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf2.x = PosEsf1.x + Rad2; } } if (LimL >= (PosEsf2.x - Rad)) { PosEsf2.x = LimL + Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf1.x = PosEsf2.x + Rad2; } } } if (Input.GetKey(KeyCode.A)) { LimR = LimR - 0.05f; LimL = LimL - 0.05f; if (LimR <= (PosEsf1.x + Rad)) { PosEsf1.x = LimR - Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf2.x = PosEsf1.x - Rad2; } } if (LimR <= (PosEsf2.x + Rad)) { PosEsf2.x = LimR - Rad; if (Mathf.Abs(Mathf.Sqrt(Mathf.Pow((PosEsf1.z - PosEsf2.z), 2) + Mathf.Pow((PosEsf1.x - PosEsf2.x), 2))) <= (Rad2)) { PosEsf1.x = PosEsf2.x - Rad2; } } } gameObject.GetComponent <Transform>().position = PosEsf1; Sphere2.GetComponent <Transform>().position = PosEsf2; }
void Start() { Sphere2 = GameObject.Find("Esf2"); PosEsf2 = Sphere2.GetComponent <Transform>().position; V1x = 0; V1z = 0; V2x = 0; V2z = 0; M1 = 1; M2 = 1; }