OnClick
How do I use On Click
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
12 | void OnClick() | 1 |
7 | void OnClick() { | 2 |
8 | public void OnClick() | 3 |
11 | public void OnClick() | 4 |
95 | if( currentGo == lastGo ) lastGo.SendMessage( "OnClick", SendMessageOptions.DontRequireReceiver ); | 5 |
28 |
OnClickDestroy ocd = go.GetComponent |
6 |
26 | public void OnClick() | 7 |
12 | void OnClick() | 8 |
19 | public void OnClick() | 9 |
18 | public void OnClick() | 10 |
File name: InstantiateCube.cs
Copy
12 void OnClick()
13 {
14 if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
15 {
16 // only use PhotonNetwork.Instantiate while in a room.
17 return;
18 }
19
20 switch (InstantiateType)
21 {
22 case 0:
23 PhotonNetwork.Instantiate(Prefab.name, this.transform.position + 3*Vector3.up, Quaternion.identity, 0);
24 break;
25 case 1:
26 PhotonNetwork.InstantiateSceneObject(Prefab.name, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity, 0, null);
27 break;
28 }
29 }
File name: OnClickRequestOwnership.cs
Copy
8 public void OnClick()
9 {
10 if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11 {
12 Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13 this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14 }
15 else
16 {
17 if( this.photonView.ownerId == PhotonNetwork.player.ID )
18 {
19 Debug.Log( "Not requesting ownership. Already mine." );
20 return;
21 }
22
23 this.photonView.RequestOwnership();
24 }
25 }
File name: OnClickCallMethod.cs
Copy
11 public void OnClick()
12 {
13 if (this.TargetGameObject == null || string.IsNullOrEmpty(this.TargetMethod))
14 {
15 Debug.LogWarning(this + " can't call, cause GO or Method are empty.");
16 return;
17 }
18
19 this.TargetGameObject.SendMessage(this.TargetMethod);
20 }
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 }
File name: ManualPhotonViewAllocator.cs
Copy
23 public void InstantiateRpc(int viewID)
24 {
25 GameObject go = GameObject.Instantiate(Prefab, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity) as GameObject;
26 go.GetPhotonView().viewID = viewID;
27
28 OnClickDestroy ocd = go.GetComponent
29 ocd.DestroyByRpc = true;
30 }
File name: OnClickDestroy.cs
Copy
26 public void OnClick()
27 {
28 if (!DestroyByRpc)
29 {
30 PhotonNetwork.Destroy(this.gameObject);
31 }
32 else
33 {
34 this.photonView.RPC("DestroyRpc", PhotonTargets.AllBuffered);
35 }
36 }
File name: OnClickInstantiate.cs
Copy
12 void OnClick()
13 {
14 if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
15 {
16 // only use PhotonNetwork.Instantiate while in a room.
17 return;
18 }
19
20 switch (InstantiateType)
21 {
22 case 0:
23 PhotonNetwork.Instantiate(Prefab.name, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity, 0);
24 break;
25 case 1:
26 PhotonNetwork.InstantiateSceneObject(Prefab.name, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity, 0, null);
27 break;
28 }
29 }
File name: OnClickLoadSomething.cs
Copy
19 public void OnClick()
20 {
21 switch (ResourceTypeToLoad)
22 {
23 case ResourceTypeOption.Scene:
24 Application.LoadLevel(ResourceToLoad);
25 break;
26 case ResourceTypeOption.Web:
27 Application.OpenURL(ResourceToLoad);
28 break;
29 }
30 }
Download file with original file name:OnClick
OnClick 131 lượt xem
Gõ tìm kiếm nhanh...