84 lines
2.6 KiB
C#
84 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class MoveSystemMaterials : MonoBehaviour
|
|
{
|
|
public GameObject correctForm;
|
|
private bool moving, finish;
|
|
private float startPosX, startPosY;
|
|
// public Text texto;
|
|
//public string pais;
|
|
private Vector3 resetposition;
|
|
public string namesresources;
|
|
|
|
void Start()
|
|
{
|
|
StartCoroutine(WaitForImages());
|
|
resetposition = this.transform.localPosition;
|
|
}
|
|
|
|
IEnumerator WaitForImages()
|
|
{
|
|
while (GamesResourcesFinder.instance.gameReady == false)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
GetComponent<SpriteRenderer>().sprite = GamesResourcesFinder.instance.AskForImage(namesresources);
|
|
Destroy(GetComponent<BoxCollider2D>());
|
|
gameObject.AddComponent<BoxCollider2D>();
|
|
}
|
|
|
|
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);
|
|
this.gameObject.SetActive(false);
|
|
finish = true;
|
|
GameObject.Find("Controller").GetComponent<CheckWinMaterials>().AddPoints();
|
|
|
|
//StartCoroutine(NextCountry(2));
|
|
}
|
|
else
|
|
{
|
|
this.transform.localPosition = new Vector3(resetposition.x, resetposition.y, resetposition.z);
|
|
}
|
|
}
|
|
}
|