Dragging









How do I use Dragging
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: ClickAndDrag.cs Copy
11  void Update ()
12  {
13         if (!photonView.isMine)
14         {
15             return;
16         }
17
18      InputToEvent input = Camera.main.GetComponent();
19      if (input == null) return;
20         if (!following)
21         {
22             if (input.Dragging)
23             {
24                 camOnPress = this.transform.position;
25                 following = true;
26             }
27             else
28             {
29                 return;
30             }
31         }
32         else
33         {
34             if (input.Dragging)
35             {
36                 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37                 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38             }
39             else
40             {
41                 camOnPress = Vector3.zero;
42                 following = false;
43             }
44         }
45  }
File name: InputToEvent.cs Copy
22     {
23         get { return this.Dragging ? this.currentPos - pressedPosition : Vector2.zero; }
24     }
File name: InputToEvent.cs Copy
78     private void Press( Vector2 screenPos )
79     {
80         pressedPosition = screenPos;
81         this.Dragging = true;
82
83         lastGo = RaycastObject( screenPos );
84         if( lastGo != null )
85         {
86             lastGo.SendMessage( "OnPress", SendMessageOptions.DontRequireReceiver );
87         }
88     }
File name: InputToEvent.cs Copy
90     private void Release( Vector2 screenPos )
91     {
92         if( lastGo != null )
93         {
94             GameObject currentGo = RaycastObject( screenPos );
95             if( currentGo == lastGo ) lastGo.SendMessage( "OnClick", SendMessageOptions.DontRequireReceiver );
96             lastGo.SendMessage( "OnRelease", SendMessageOptions.DontRequireReceiver );
97             lastGo = null;
98         }
99
100         pressedPosition = Vector2.zero;
101         this.Dragging = false;
102     }

Dragging 112 lượt xem

Gõ tìm kiếm nhanh...