83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MoveSystem : MonoBehaviour
|
|
{
|
|
public GameObject correctForm, nextCountry;
|
|
private bool moving, finish;
|
|
private float startPosX, startPosY;
|
|
public Text texto;
|
|
public string pais;
|
|
private Vector3 resetposition;
|
|
private AudioSource audio;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
resetposition = this.transform.localPosition;
|
|
audio = GetComponent<AudioSource>();
|
|
}
|
|
|
|
// 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);
|
|
finish = true;
|
|
GameObject.Find("Check").GetComponent<CheckWIn>().AddPoints();
|
|
texto.text = "I am from " + pais;
|
|
audio.Play();
|
|
StartCoroutine(NextCountry(4));
|
|
}
|
|
else
|
|
{
|
|
this.transform.localPosition = new Vector3(resetposition.x, resetposition.y, resetposition.z);
|
|
}
|
|
}
|
|
|
|
IEnumerator NextCountry(float waitTime)
|
|
{
|
|
yield return new WaitForSeconds(waitTime);
|
|
correctForm.SetActive(false);
|
|
this.gameObject.SetActive(false);
|
|
nextCountry.SetActive(true);
|
|
}
|
|
|
|
}
|