using UnityEngine using System Collections public class Drag MonoBehav

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using UnityEngine;
using System.Collections;
public class Drag : MonoBehaviour
{
public Ray2D ray;
public RaycastHit hit;
public Camera Camera1;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
RaycastHit2D aHit = new RaycastHit2D();
if (Camera1.orthographic)
{
aHit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Camera.main.ScreenToWorldPoint(Input.mousePosition));
Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), Camera.main.ScreenToWorldPoint(Input.mousePosition));
if (aHit)
{
if (aHit.collider.gameObject.tag == "DestroybleBlock")
{
Destroy(aHit.collider.gameObject);
}
aHit.collider.rigidbody2D.velocity = new Vector2(0, 0);
aHit.collider.rigidbody2D.MovePosition(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, aHit.collider.transform.position.y));
}
}
}
}
}