OnPress









How do I use On Press
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: OnClickRightDestroy.cs Copy
5     public void OnPressRight()
6     {
7         Debug.Log("RightClick Destroy");
8         PhotonNetwork.Destroy(gameObject);
9     }
File name: InputToEvent.cs Copy
32     void Update()
33     {
34         if( DetectPointedAtGameObject )
35         {
36             goPointedAt = RaycastObject( Input.mousePosition );
37         }
38
39         if( Input.touchCount > 0 )
40         {
41             Touch touch = Input.GetTouch( 0 );
42             this.currentPos = touch.position;
43
44             if( touch.phase == TouchPhase.Began )
45             {
46                 Press( touch.position );
47             }
48             else if( touch.phase == TouchPhase.Ended )
49             {
50                 Release( touch.position );
51             }
52
53             return;
54         }
55
56         currentPos = Input.mousePosition;
57         if( Input.GetMouseButtonDown( 0 ) )
58         {
59             Press( Input.mousePosition );
60         }
61         if( Input.GetMouseButtonUp( 0 ) )
62         {
63             Release( Input.mousePosition );
64         }
65
66         if( Input.GetMouseButtonDown( 1 ) )
67         {
68             pressedPosition = Input.mousePosition;
69             lastGo = RaycastObject( pressedPosition );
70             if( lastGo != null )
71             {
72                 lastGo.SendMessage( "OnPressRight", SendMessageOptions.DontRequireReceiver );
73             }
74         }
75     }
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     }

OnPress 130 lượt xem

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