using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CtrlMSRoupas : MonoBehaviour { public GameObject correctForm; private bool moving, finish; private float startPosX, startPosY; private Vector3 resetposition; public CckW cck; // Start is called before the first frame update void Start() { resetposition = this.transform.localPosition; cck = GameObject.Find("Game").GetComponent(); } // Update is called once per frame void Update() { if (finish == false) { if (moving) { Vector3 mousePos; mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(mousePos); this.gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, this.gameObject.transform.localPosition.z); } } } private void OnMouseDown() { Debug.Log("Apertou"); if (Input.GetMouseButtonDown(0)) { Vector3 mousePos; mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(mousePos); startPosX = mousePos.x - this.transform.localPosition.x; startPosY = mousePos.y - this.transform.localPosition.y; moving = true; } } private void OnMouseUp() { moving = false; if (Mathf.Abs(this.transform.localPosition.x - correctForm.transform.localPosition.x) <= 3f && Mathf.Abs(this.transform.localPosition.y - correctForm.transform.localPosition.y) <= 3f && correctForm.active) { this.transform.position = new Vector3(correctForm.transform.position.x, correctForm.transform.position.y, correctForm.transform.position.z); Destroy(this.GetComponent()); cck.CorrectSound(); finish = true; GameObject.Find("Game").GetComponent().AddPoints(); } else { this.transform.localPosition = new Vector3(resetposition.x, resetposition.y, resetposition.z); cck.WrongSound(); } } }