AddScore
How do I use Add Score
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: OnPickedUpScript.cs
Copy
6 public void OnPickedUp(PickupItem item)
7 {
8 if (item.PickupIsMine)
9 {
10 Debug.Log("I picked up something. That's a score!");
11 PhotonNetwork.player.AddScore(1);
12 }
13 else
14 {
15 Debug.Log("Someone else picked up something. Lucky!");
16 }
17 }
File name: PunPlayerScores.cs
Copy
23 public static void AddScore(this PhotonPlayer player, int scoreToAddToCurrent)
24 {
25 int current = player.GetScore();
26 current = current + scoreToAddToCurrent;
27
28 Hashtable score = new Hashtable(); // using PUN's implementation of Hashtable
29 score[PunPlayerScores.PlayerScoreProp] = current;
30
31 player.SetCustomProperties(score); // this locally sets the score and will sync it in-game asap.
32 }
File name: GameManager.cs
Copy
278 public void GameOver(GCPlayer winner, GameOverType gameOverType) {
279 AddGame();
280 switch (gameOverType) {
281 case GameOverType.CHECKMATE:
282 if (winner == p2) {
283 winnerText.text = "CHECKMATE: BLACK wins";
284 AddScore(PLAYER_BLACK);
285 } else if (winner == p1) {
286 winnerText.text = "CHECKMATE: WHITE wins";
287 AddScore(PLAYER_WHITE);
288 }
289 break;
290 case GameOverType.STALEMATE:
291 winnerText.text = "STALEMATE: It's a tie";
292 break;
293 case GameOverType.OUT_OF_TIME:
294 if (winner == p1) {
295 winnerText.text = "OUT OF TIME: WHITE wins";
296 AddScore(PLAYER_WHITE);
297 } else if (winner == p2) {
298 winnerText.text = "OUT OF TIME: BLACK wins";
299 AddScore(PLAYER_BLACK);
300 }
301 break;
302 }
303 continueButton.SetActive(true);
304 }
File name: GameManager.cs
Copy
321 public void AddScore(string playerString) {
322 int newScore = PlayerPrefs.GetInt(playerString,0) + 1;
323 PlayerPrefs.SetInt(playerString,newScore);
324
325 int maxScore = PlayerPrefs.GetInt(SCORE_MAX,0);
326 if (newScore >= maxScore) {
327 End();
328 }
329 }
File name: Animal.cs
Copy
300 public void OnCollisionEnter2D(Collision2D otherCollision)
301 {
302 if (otherCollision.gameObject.name == MapObjectNames.GroundObject)
303 {
304 state = RUN;
305 stepJump = 2;
306 isSprings = false;
307 }
308 else if (otherCollision.gameObject.name == "Bullet")
309 {
310 if (gameObject.GetComponent
311 if (animalIndex != otherCollision.gameObject.GetComponent
312 {
313 if (otherCollision.gameObject.GetComponent
314 {
315 if (otherCollision.gameObject.GetComponent
316 {
317 gameScreen.addScore(10, gameObject.transform.localPosition);
318 gameScreen.setCombo(1, otherCollision.gameObject.GetComponent
319 }
320 gameScreen.AnimalcollisionWithBullet(gameObject, otherCollision.gameObject);
321 }
322 }
323 }
324 }
File name: Animal.cs
Copy
326 public void OnTriggerEnter2D(Collider2D otherCollider)
327 {
328 string mapObjectName = otherCollider.gameObject.name;
329
330 if (mapObjectName == MapObjectNames.MarkObject && animalIndex != 0)
331 {
332 int r = Random.Range(0, 2);
333 if (r == 0)
334 if (!isBooster && !isSprings)
335 Jump();
336 }
337 else if (mapObjectName == MapObjectNames.HoleObject && animalIndex != 0)
338 {
339 Jump();
340 }
341 else if (mapObjectName == MapObjectNames.BoostObject)
342 {
343 booster();
344 stepJump = 2;
345 if (animalIndex == 0)
346 {
347 gameScreen.setCombo(6);
348 gameScreen.addScore(5, transform.localPosition);
349 }
350 }
351 else if (mapObjectName == MapObjectNames.SpringsObject)
352 {
353 springs();
354 stepJump = 2;
355 if (animalIndex == 0)
356 {
357 gameScreen.setCombo(7);
358 gameScreen.addScore(5, transform.localPosition);
359 }
360 }
361 else if (mapObjectName == MapObjectNames.RevivalObject)
362 {
363 setRevivalPosition(otherCollider.gameObject.GetComponent
364 }
365 else if (mapObjectName == MapObjectNames.DeadLine)
366 {
367 if (animalIndex == 0)
368 {
369 gameScreen.showRevivalTask(2, EmotionType.BUON);
370 }
371 isRevival = true;
372 setStand(false, 0, STATE_RUN);
373 IsProtected = false;
374 revivalTime = 2;
375 }
376 else if (mapObjectName == MapObjectNames.SkillObject)
377 {
378 gameScreen.eatSkillRandom(otherCollider.gameObject.GetComponent
379 otherCollider.gameObject.transform.localPosition, animalIndex);
380 if (animalIndex == 0)
381 SoundManager.playSound("Sounds/anskill");
382
383 }
384 else if (mapObjectName == MapObjectNames.FinishObject && animalIndex == 0)
385 {
386 gameScreen.finishGame();
387
388 Destroy(otherCollider);//cho nay de tranh lap lai nhieu lan ham finishgame
389 }
390 else if (mapObjectName == MapObjectNames.Bullet)
391 {
392 if (animalIndex != otherCollider.gameObject.GetComponent
393 {
394 if (IsProtected) return;
395 gameScreen.AnimalcollisionWithBullet(gameObject, otherCollider.gameObject);
396 isSprings = false;
397 isBooster = false;
398
399 if (otherCollider.gameObject.GetComponent
400 {
401 gameScreen.addScore(10, gameObject.transform.localPosition);
402 gameScreen.setCombo(1, otherCollider.gameObject.GetComponent
403 }
404 else
405 {
406 gameScreen.setCombo(-1);
407 }
408 }
409 }
410 else if (otherCollider.gameObject.name == MapObjectNames.Coin && animalIndex == 0)//if is player
411 {
412 gameScreen.addDurtGold(otherCollider.gameObject.transform.localPosition);
413 Destroy(otherCollider.gameObject);
414 gameScreen.m_gold++;
415 SoundManager.playSound("Sounds/anxu");
416 }
417 }
File name: GameScreen.cs
Copy
460 public void addScore(int score, Vector3 position)
461 {
462 if (score == 5)
463 {
464 GameObject addScore = new GameObject("Score");
465 addScore.transform.parent = scoreLayer.transform;
466 addScore.transform.localPosition = new Vector3(position.x, position.y, -1);
467 addScore.AddComponent
468 addScore.layer = LayerMask.NameToLayer("Map");
469 addScore.GetComponent
470 addScore.AddComponent
471 Destroy(addScore, 1.5f);
472 }
473 else if (score == 10)
474 {
475 GameObject addScore = new GameObject("Score");
476 addScore.transform.parent = scoreLayer.transform;
477 addScore.transform.localPosition = new Vector3(position.x, position.y, -1);
478 addScore.AddComponent
479 addScore.layer = LayerMask.NameToLayer("Map");
480 addScore.GetComponent
481 addScore.AddComponent
482 new ActionMoveTo(position.x + 2, position.y + 1.5f, 1.5f),
483 new ActionRunnable(delegate() {
484 Destroy(addScore);
485 })
486 ));
487 // Destroy(addScore, 1.5f);
488 }
489 m_score += score;
490 }
File name: GameScreen.cs
Copy
492 public void eatSkillRandom(SkillType type, Vector3 position, int animalIndex)
493 {
494 if (animalIndex == 0)
495 {
496 if (useSkills)
497 {
498 GameObject skillRand = new GameObject("SkilRand");
499 skillRand.transform.parent = scoreLayer.transform;
500 skillRand.transform.localPosition = new Vector3(position.x, position.y, -1);
501 skillRand.AddComponent
502 skillRand.layer = LayerMask.NameToLayer("Map");
503 skillRand.GetComponent
504 skillRand.AddComponent
505 new ActionMoveTo(position.x + 3, position.y + 1.5f, 1.5f),
506 new ActionRunnable(delegate() {
507 Destroy(skillRand);
508 })
509 ));
510 skillRand.transform.localScale = new Vector3(0.5f, 0.5f, skillRand.transform.localScale.z);
511 //Destroy(skillRand, 1.5f);
512
513 buttonSkills.eateSkill(type);
514
515 addScore(5, position);
516 }
517 }
518 else
519 {
520 int ra = Random.Range(1, 100);
521 if(ra <= perSkills[Attr.currentLevel])
522 addSkill(type, animalIndex);
523 }
524 }
AddScore 133 lượt xem
Gõ tìm kiếm nhanh...