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; } } }
// Use this for initialization void Start() { atb = this.GetComponent <AtribRocks>(); ReloadLayout = random.Max; }
// Use this for initialization void Start() { atb = this.GetComponent<AtribRocks>(); ReloadLayout = random.Max; }
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.collider != null) { bdT = true; //designamos el objeto a mover dependiendo del collider tocado player = GameObject.Find(hit.collider.gameObject.name); } else { player = temp; } } if (player.tag.CompareTo("roca") == 0) { //Baja la vida de la roca if (GeneralAttrib.type == 1) { atb = player.GetComponent<AtribRocks>(); contV++; perderVidas(contV); } if (atb.life <= 0) { //Animacion transform.FindChild("GameObject").GetComponent<Animator>().SetTrigger("life"); if (Input.GetTouch(0).phase == TouchPhase.Began) { bdT = false; } if (Input.GetTouch(0).phase == TouchPhase.Ended) { bdT = true; } if (bdT) { //PONGA SU CODIGO AQUI //AQUI //AQUI //AQUIIII Debug.Log((Vector2.Scale(Input.GetTouch(0).position, Input.GetTouch(0).deltaPosition) * Input.GetTouch(0).deltaTime).x); Debug.Log((Vector2.Scale(Input.GetTouch(0).position, Input.GetTouch(0).deltaPosition) * Input.GetTouch(0).deltaTime).y); RigidB.AddForce(Vector2.Scale(Input.GetTouch(0).position, Input.GetTouch(0).deltaPosition) * Input.GetTouch(0).deltaTime); } else { player.transform.position = new Vector2(Pos.x, Pos.y); } } else { transform.FindChild("GameObject").GetComponent<Animator>().SetTrigger("Activate"); } } if (Input.GetTouch(0).phase == TouchPhase.Ended) { contV = 0; } } }
// Use this for initialization void Start() { atb = this.GetComponent<AtribRocks>(); ReloadLayout = GeneralAttrib.maxi; }