-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewBehaviourScript.cs
More file actions
44 lines (38 loc) · 1.06 KB
/
NewBehaviourScript.cs
File metadata and controls
44 lines (38 loc) · 1.06 KB
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
44
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
public class NewBehaviourScript : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
private Vector3 curScreenPoint;
private Vector3 curPosition;
private bool isPressed;
private float mouseZ;
private float transformZ;
protected virtual void Update ()
{
if (Input.GetKeyDown (KeyCode.I))
isPressed = true;
if (Input.GetKeyDown (KeyCode.O))
isPressed = false;
}
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
mouseZ = Input.mousePosition.y;
}
void OnMouseDrag()
{
transformZ =(float) (.1*(Input.mousePosition.y - mouseZ));
if (isPressed)
{
curScreenPoint = new Vector3 (screenPoint.x, screenPoint.y,
screenPoint.z + transformZ );
}
else
curScreenPoint = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint);
transform.position = curPosition;
}
}