public void Dragging() { if (Input.touchCount > 0) { if (Input.GetTouch (0).phase == TouchPhase.Began) { //Cambia la posicion del touch por la posicion en la pantalla, es como un render Pos = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position); //Usamos un raycast 2d para hallar el collider RaycastHit2D hit = Physics2D.Raycast (new Vector2 (Pos.x, Pos.y), Vector2.zero); if (hit != null && hit.collider != null) { bd = true; //designamos el objeto a mover dependiendo del collider tocado player = GameObject.Find (hit.collider.gameObject.name); if(player.GetComponent<AtribRocks>()!=null) { atb=player.GetComponent<AtribRocks>(); contV++; perderVidas(contV); } else { att2=player.GetComponent<TrapsAtt>(); contV++; perderVidas(contV); } } else { player = temp; } } if ((player.gameObject.name != "Temporito")&&(atb.life<=0)&& (atb.layer==30)) { // Invoke ("TemporalTouch", 0.001f); Pos = Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position); BorrarLuego(); if(bdT) { Velocidad.AddForce(new Vector2 (DistanceX * 1f , DistanceY * 1f) ); } else { player.transform.position = new Vector2( Pos.x, Pos.y ); } } if (Input.GetTouch (0).phase == TouchPhase.Ended) { contV=0; } } }
public void Dragging() { if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Began) { //Cambia la posicion del touch por la posicion en la pantalla, es como un render Pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); //Usamos un raycast 2d para hallar el collider RaycastHit2D hit = Physics2D.Raycast(new Vector2(Pos.x, Pos.y), Vector2.zero); if (hit != null && hit.collider != null) { bd = true; //designamos el objeto a mover dependiendo del collider tocado player = GameObject.Find(hit.collider.gameObject.name); if (player.GetComponent <AtribRocks>() != null) { atb = player.GetComponent <AtribRocks>(); contV++; perderVidas(contV); } else { att2 = player.GetComponent <TrapsAtt>(); contV++; perderVidas(contV); } } else { player = temp; } } if ((player.gameObject.name != "Temporito") && (atb.life <= 0) && (atb.layer == 30)) { // Invoke ("TemporalTouch", 0.001f); Pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); BorrarLuego(); if (bdT) { Velocidad.AddForce(new Vector2(DistanceX * 1f, DistanceY * 1f)); } else { player.transform.position = new Vector2(Pos.x, Pos.y); } } if (Input.GetTouch(0).phase == TouchPhase.Ended) { contV = 0; } } }
// Update is called once per frame void Update() { if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Began) { //Cambia la posicion del touch por la posicion en la pantalla, es como un render Pos = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); //Usamos un raycast 2d para hallar el collider RaycastHit2D hit = Physics2D.Raycast(new Vector2(Pos.x, Pos.y), Vector2.zero); if(hit.collider!=null) { if (player.tag.CompareTo("Trampa1") == 0) { att = player.GetComponent<TrapsAtt>(); att.life--; } else if (player.tag.CompareTo("Power") == 0) { powA = player.GetComponent<powerupsAtt>(); powA.powerVida--; } else if (player.tag.CompareTo("Trophie") == 0) { PlayerPrefs.SetInt("trop" + player.GetComponent<TrophiesAtt>().tipo, 1); Destroy(player); } } } } }