using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class drag : MonoBehaviour
{
private Vector3 offset;
private int score = 1;
//public float distance = 1f;
//public LayerMask mask;
/*void FixedUpdate(){
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.left);
Debug.DrawRay(transform.position, -Vector2.left * distance);
if (hit.collider != null){
Debug.Log(hit.collider.name);
}
}*/
void OnMouseDown(){
if (score == 1){
offset = gameObject.transform.position -
Camera.main.ScreenToWorldPoint(
new Vector3(Input.mousePosition.x, Input.mousePosition.y, -10.0f));
}
}
void OnMouseDrag(){
if (score == 1){
Vector3 newPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, -10.0f);
transform.position = Camera.main.ScreenToWorldPoint(newPosition) + offset;
}
}
void OnTriggerEnter2D(Collider2D other){
if(other.gameObject.GetComponent<objTags>()){
List<string> tags = other.gameObject.GetComponent<objTags>().tags;
bool isNorm = false;
foreach (string tag in tags){
if (tag.Equals("norm"))
isNorm = true;
}
if (isNorm){
Debug.Log(other.gameObject.transform.position);
transform.position = new Vector3(other.gameObject.transform.position.x,
other.gameObject.transform.position.y, transform.position.z);
StartCoroutine(dragPause());
}
}
}
IEnumerator dragPause(){
// while (true){
score = 0;
yield return new WaitForSeconds(0.1f);
score = 1;
// }
}
}