All









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

Featured Snippets


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: ChatGui.cs Copy
95     public void Update()
96     {
97         if (this.chatClient != null)
98         {
99             this.chatClient.Service(); // make sure to call this regularly! it limits effort internally, so calling often is ok!
100         }
101     }
File name: NamePickGui.cs Copy
15     public void Awake()
16     {
17         this.guiCenteredRect = new Rect(Screen.width/2-GuiSize.x/2, Screen.height/2-GuiSize.y/4, GuiSize.x, GuiSize.y);
18         this.chatComponent = this.GetComponent();
19
20         if (this.chatComponent != null && chatComponent.enabled)
21         {
22             Debug.LogWarning("When using the NamePickGui, ChatGui should be disabled initially.");
23
24             if (this.chatComponent.chatClient != null)
25             {
26                 this.chatComponent.chatClient.Disconnect();
27             }
28             this.chatComponent.enabled = false;
29         }
30
31         string prefsName = PlayerPrefs.GetString(NamePickGui.UserNamePlayerPref);
32         if (!string.IsNullOrEmpty(prefsName))
33         {
34             this.InputLine = prefsName;
35         }
36     }
File name: BallControl.cs Copy
10  void GoBall() {
11   float rand = Random.Range (0, 2);
12   if (rand < 1) {
13    rb2d.AddForce (new Vector2 (20, -15));
14   } else {
15    rb2d.AddForce (new Vector2 (-20, -15));
16   }
17  }
File name: BallControl.cs Copy
20  void Start () {
21   rb2d = GetComponent ();
22   Invoke ("GoBall", 2);
23  }
File name: BallControl.cs Copy
25  void ResetBall() {
26   vel = new Vector2 (0, 0);
27   rb2d.velocity = vel;
28   transform.position = Vector2.zero;
29  }
File name: BallControl.cs Copy
31  void RestartGame() {
32   ResetBall ();
33   Invoke ("GoBall", 1);
34  }
File name: GameManager.cs Copy
15  void Start () {
16   theBall = GameObject.FindGameObjectWithTag ("Ball");
17  }
File name: GameManager.cs Copy
19  public static void Score(string wallID) {
20   if (wallID == "RightWall") {
21    PlayerScore1++;
22   } else {
23    PlayerScore2++;
24   }
25  }
File name: GameManager.cs Copy
27  void OnGUI() {
28   GUI.skin = layout;
29   GUI.Label (new Rect (Screen.width / 2 - 150 - 12, 20, 100, 100), "" + PlayerScore1);
30   GUI.Label (new Rect (Screen.width / 2 + 150 + 12, 20, 100, 100), "" + PlayerScore2);
31
32   if (GUI.Button (new Rect (Screen.width / 2 - 60, 35, 120, 53), "RESTART")) {
33    PlayerScore1 = 0;
34    PlayerScore2 = 0;
35    theBall.SendMessage ("RestartGame", 0.5f, SendMessageOptions.RequireReceiver);
36   }
37
38   if (PlayerScore1 == 10) {
39    GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER ONE WINS");
40    theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
41   } else if (PlayerScore2 == 10) {
42    GUI.Label (new Rect (Screen.width / 2 - 150, 200, 2000, 1000), "PLAYER TWO WINS");
43    theBall.SendMessage ("ResetBall", null, SendMessageOptions.RequireReceiver);
44   }
45  }

Download file with original file name:All

All 195 lượt xem

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