void Update() { //if (Input.touchCount > 0 && !locked) //SEM SIMULADOR if (!locked) { if (transform.position.x != initialPosition.x && initialPosition.y != transform.position.y) { transform.localScale = new Vector3(xN, yN, z); } else { transform.localScale = new Vector3(x, y, z); } //Touch touch = Input.GetTouch(0);//simulatess();//Input.GetTouch(0); SEM SIMULADOR Touch touch = simulatess();//Input.GetTouch(0); SEM SIMULADOR Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position); switch (touch.phase) { case TouchPhase.Began: if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos)) { //Debug.Log(slider); deltaX = touchPos.x - transform.position.x; deltaY = touchPos.y - transform.position.y; } break; case TouchPhase.Moved: if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos)) { if (gameController.lockKK == 0) { gameController.lockKK = 4; } else if (gameController.lockKK == 4) { transform.position = new Vector3(touchPos.x - deltaX, touchPos.y - deltaY, z); this.GetComponent <SpriteRenderer>().sortingOrder = 7; } else { gameController.resizeColiderMin(this.GetComponent <BoxCollider2D>()); } } break; case TouchPhase.Ended: if (place != null && place.tag != "ok" && (Mathf.Abs(transform.position.x - place.position.x) <= 1.0f && Mathf.Abs(transform.position.y - place.position.y) <= 1.0f)) { transform.position = new Vector3(place.position.x, place.position.y, z); locked = true; transform.localScale = new Vector3(x, y, z); gameController.addRight(); gameController.playFx(fxLetra); place.tag = "ok"; place = null; } else if (place2 != null && place2.tag != "ok" && (Mathf.Abs(transform.position.x - place2.position.x) <= 1.0f && Mathf.Abs(transform.position.y - place2.position.y) <= 1.0f)) { transform.position = new Vector3(place2.position.x, place2.position.y, z); locked = true; transform.localScale = new Vector3(x, y, z); gameController.addRight(); gameController.playFx(fxLetra); place2.tag = "ok"; place2 = null; } else { if (initialPosition.x != transform.position.x) { transform.position = new Vector3(initialPosition.x, initialPosition.y, z); gameController.addError(); } } gameController.lockKK = 0; gameController.resizeColiderMax(this.GetComponent <BoxCollider2D>(), this.GetComponent <SpriteRenderer>()); break; } } }
void Update() { //if (Input.touchCount > 0 && !locked) //SEM SIMULADOR if (!locked) { //Debug.Log("Opaaa"); if (transform.position.x != initialPosition.x && initialPosition.y != transform.position.y) { transform.localScale = new Vector3(xN, yN); this.GetComponent <SpriteRenderer>().sortingOrder = 11; } else { this.GetComponent <Renderer>().sortingOrder = 10; transform.localScale = new Vector2(x, y); } //Touch touch = Input.GetTouch(0);//simulatess();//Input.GetTouch(0); SEM SIMULADOR Touch touch = simulatess();//Input.GetTouch(0); SEM SIMULADOR Vector2 touchPos = Camera.main.ScreenToWorldPoint(touch.position); switch (touch.phase) { case TouchPhase.Began: if (!estaArrastando) { //StartCoroutine("waith2S"); estaArrastando = true; //print("COMEÇO ESTATA ARRASTANDO O "+ letraMove); if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos)) { //Debug.Log(slider); deltaX = touchPos.x - transform.position.x; deltaY = touchPos.y - transform.position.y; } } break; case TouchPhase.Moved: //print("COMEÇO ESTATA ARRASTANDO O "+ letraMove); if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos)) { transform.position = new Vector2(touchPos.x - deltaX, touchPos.y - deltaY); } break; case TouchPhase.Ended: estaArrastando = false; if (letraPlace != null && (Mathf.Abs(transform.position.x - letraPlace.transform.position.x) <= 2.0f && Mathf.Abs(transform.position.y - letraPlace.transform.position.y) <= 2.0f)) { transform.position = new Vector2(letraPlace.transform.position.x, letraPlace.transform.position.y); locked = true; transform.localScale = new Vector2(x, y); letraPlace.SetActive(false); this.GetComponent <Renderer>().sortingOrder = 10; this.GetComponent <BoxCollider2D>().enabled = false; gameController.addRight(); //gameController.playFx(fxLetra); print("DESATIVAR O PLACE " + letraMove); } else if (letraPlace != null && (Mathf.Abs(transform.position.x - letraPlace.transform.position.x) <= 2.0f && Mathf.Abs(transform.position.y - letraPlace.transform.position.y) <= 2.0f)) { transform.position = new Vector2(letraPlace.transform.position.x, letraPlace.transform.position.y); locked = true; transform.localScale = new Vector2(x, y); letraPlace.SetActive(false); this.GetComponent <Renderer>().sortingOrder = 10; this.GetComponent <BoxCollider2D>().enabled = false; gameController.addRight(); //gameController.playFx(fxLetra); } else { //Debug.Log(initialPosition.x + "-" + initialPosition.y); if (initialPosition.x != transform.position.x) { transform.position = new Vector2(initialPosition.x, initialPosition.y); //gameController.addError(); } } break; } } else //adicionado para sempre mater a posição inicial atualizada. { initialPosition = transform.position; } }