Health









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

Featured Snippets


File name: PhotonStatsGui.cs Copy
77     public void TrafficStatsWindow(int windowID)
78     {
79         bool statsToLog = false;
80         TrafficStatsGameLevel gls = PhotonNetwork.networkingPeer.TrafficStatsGameLevel;
81         long elapsedMs = PhotonNetwork.networkingPeer.TrafficStatsElapsedMs / 1000;
82         if (elapsedMs == 0)
83         {
84             elapsedMs = 1;
85         }
86
87         GUILayout.BeginHorizontal();
88         this.buttonsOn = GUILayout.Toggle(this.buttonsOn, "buttons");
89         this.healthStatsVisible = GUILayout.Toggle(this.healthStatsVisible, "health");
90         this.trafficStatsOn = GUILayout.Toggle(this.trafficStatsOn, "traffic");
91         GUILayout.EndHorizontal();
92
93         string total = string.Format("Out|In|Sum:\t{0,4} | {1,4} | {2,4}", gls.TotalOutgoingMessageCount, gls.TotalIncomingMessageCount, gls.TotalMessageCount);
94         string elapsedTime = string.Format("{0}sec average:", elapsedMs);
95         string average = string.Format("Out|In|Sum:\t{0,4} | {1,4} | {2,4}", gls.TotalOutgoingMessageCount / elapsedMs, gls.TotalIncomingMessageCount / elapsedMs, gls.TotalMessageCount / elapsedMs);
96         GUILayout.Label(total);
97         GUILayout.Label(elapsedTime);
98         GUILayout.Label(average);
99
100         if (this.buttonsOn)
101         {
102             GUILayout.BeginHorizontal();
103             this.statsOn = GUILayout.Toggle(this.statsOn, "stats on");
104             if (GUILayout.Button("Reset"))
105             {
106                 PhotonNetwork.networkingPeer.TrafficStatsReset();
107                 PhotonNetwork.networkingPeer.TrafficStatsEnabled = true;
108             }
109             statsToLog = GUILayout.Button("To Log");
110             GUILayout.EndHorizontal();
111         }
112
113         string trafficStatsIn = string.Empty;
114         string trafficStatsOut = string.Empty;
115         if (this.trafficStatsOn)
116         {
117             trafficStatsIn = "Incoming: " + PhotonNetwork.networkingPeer.TrafficStatsIncoming.ToString();
118             trafficStatsOut = "Outgoing: " + PhotonNetwork.networkingPeer.TrafficStatsOutgoing.ToString();
119             GUILayout.Label(trafficStatsIn);
120             GUILayout.Label(trafficStatsOut);
121         }
122
123         string healthStats = string.Empty;
124         if (this.healthStatsVisible)
125         {
126             healthStats = string.Format(
127                 "ping: {6}[+/-{7}]ms\nlongest delta between\nsend: {0,4}ms disp: {1,4}ms\nlongest time for:\nev({3}):{2,3}ms op({5}):{4,3}ms",
128                 gls.LongestDeltaBetweenSending,
129                 gls.LongestDeltaBetweenDispatching,
130                 gls.LongestEventCallback,
131                 gls.LongestEventCallbackCode,
132                 gls.LongestOpResponseCallback,
133                 gls.LongestOpResponseCallbackOpCode,
134                 PhotonNetwork.networkingPeer.RoundTripTime,
135                 PhotonNetwork.networkingPeer.RoundTripTimeVariance);
136             GUILayout.Label(healthStats);
137         }
138
139         if (statsToLog)
140         {
141             string complete = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", total, elapsedTime, average, trafficStatsIn, trafficStatsOut, healthStats);
142             Debug.Log(complete);
143         }
144
145         // if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
146         if (GUI.changed)
147         {
148             this.statsRect.height = 100;
149         }
150
151         GUI.DragWindow();
152     }
File name: BossController.cs Copy
21  void Update () {
22   if (transform.position != targetPoint.position) {
23    transform.position = Vector3.MoveTowards (transform.position, targetPoint.position, speed * Time.deltaTime);
24   } else {
25    transform.GetComponent ().invulnerable = false;
26    transform.GetComponent ().isReadyToShoot = true;
27   }
28  }
File name: BossHealth.cs Copy
22  void InitializeBossVariables(){
23   health.maxValue = maxHealth;
24   health.value = maxHealth;
25   invulnerable = true;
26  }
File name: BossHealth.cs Copy
28  public void Health(int damage){
29   if (!invulnerable) {
30    if (!health.gameObject.activeInHierarchy) {
31     health.gameObject.SetActive (true);
32    }
33
34    if (health.value > 0) {
35     health.value -= damage;
36    }
37
38    if (health.value == 0) {
39     BossDestroyed ();
40    }
41   }
42  }
File name: EnemyHealth.cs Copy
14  void Awake(){
15   health.maxValue = maxHealth;
16   health.value = maxHealth;
17  }
File name: EnemyHealth.cs Copy
24  public void Health(int damage){
25   if(!health.gameObject.activeInHierarchy){
26    health.gameObject.SetActive (true);
27   }
28
29   if(health.value > 0){
30    health.value -= damage;
31   }
32
33   if(health.value == 0){
34    Destroy (gameObject);
35    if(!spawn){
36     spawn = true;
37     Instantiate (explosion, transform.position, Quaternion.identity);
38     Instantiate (coin, transform.position, Quaternion.identity);
39    }
40
41   }
42  }
File name: PlayerBullet.cs Copy
20  void OnTriggerEnter2D(Collider2D collider){
21   if(collider.CompareTag("Enemy")){
22    Instantiate (hit, transform.position, Quaternion.identity);
23    collider.transform.GetComponent ().Health (damage);
24    Destroy (gameObject);
25   }
26
27   if(collider.CompareTag("Boss")){
28    Instantiate (hit, transform.position, Quaternion.identity);
29    collider.transform.GetComponent ().Health (damage);
30    Destroy (gameObject);
31   }
32  }
File name: PlayerControl.cs Copy
148     void GetBonusEffect(BonusesEnum currentBonus)
149     {
150         switch (currentBonus)
151         {
152             case (BonusesEnum.bonusMoney): IncreaseScoreByBonus(); break;
153             case (BonusesEnum.bonusBullet): IncreaseBulletsByBonus(); break;
154             case (BonusesEnum.bonusHealth): IncreaseCurrentLifeByBonus(); break;
155             case (BonusesEnum.bonusSpeed): IncreaseSpeedByBonus(); break;
156         }
157
158     }
File name: SkillDescription.cs Copy
8  public SkillDescription(){
9   names = new string[]{"Fire", "Ice", "Shock", "Thunder", "Bomb", "Swap", "Shield", "Speed Up", "Health"};
10   descriptions = new string[,]{
11    {"Attack enemy by fire ball",""},
12    {"Freeze enemy by ice",""},
13    {"Stun enemy by flash",""},
14    {"Attack and stun enemies ", "whom got hit by skill"},
15    {"Attack enemy in character's ", "behind by bomb"},
16    {"Swap position with enemy ", "who got hit by skill"},
17    {"Make a shield to block ", "one attack"},
18    {"Increase character's move ", "speed by 50%"},
19    {"Increase character's", "health by 50%"}
20   };
21  }

Download file with original file name:Health

Health 144 lượt xem

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