Coin
How do I use Coin
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: CoinGeneratorScript.cs
Copy
11 public void spawnCoins (Vector3 startPosition) {
12 GameObject coin1 = coinPooler.GetPooledObject ();
13 coin1.transform.position = startPosition;
14 coin1.SetActive (true);
15
16 GameObject coin2 = coinPooler.GetPooledObject ();
17 coin2.transform.position = new Vector3 (startPosition.x - coinDistance, startPosition.y, startPosition.z);
18 coin2.SetActive (true);
19
20 GameObject coin3 = coinPooler.GetPooledObject ();
21 coin3.transform.position = new Vector3 (startPosition.x + coinDistance, startPosition.y, startPosition.z);
22 coin3.SetActive (true);
23
24 GameObject coin4 = coinPooler.GetPooledObject ();
25 coin4.transform.position = new Vector3 (startPosition.x - 2.6f, startPosition.y, startPosition.z);
26 coin4.SetActive (true);
27
28 GameObject coin5 = coinPooler.GetPooledObject ();
29 coin5.transform.position = new Vector3 (startPosition.x - 3.9f, startPosition.y, startPosition.z);
30 coin5.SetActive (true);
31 }
File name: GameManagerScript.cs
Copy
56 public void pauseGame () {
57 pausePanel.SetActive (true);
58 bestScore.text = "Best Score: " + PlayerPrefs.GetInt ("bestScore");
59 highCoinScore.text = "Best Coin Score: " +PlayerPrefs.GetInt ("bestCoinScore");
60 Time.timeScale = 0f;
61 }
File name: GameManagerScript.cs
Copy
80 public void SetCoinScore (int score) {
81 coinScore.text = "Coin: " + score;
82 }
File name: GameManagerScript.cs
Copy
88 public void gameOver (int score, int coins) {
89 coinScore.gameObject.SetActive (false);
90 pauseButton.gameObject.SetActive (false);
91 gameOverPanel.SetActive (true);
92 gameOverBestScore.text = "Your Score: " + score;
93 gameOverHighCoinScore.text = "Your Coin Score: " + coins;
94
95 }
File name: GameManagerScript.cs
Copy
111 public void ifPlayerDiedCoinScore(int score) {
112 highCoinScore.text = "Best Coin Score: " + coinScore;
113
114 if (score > Scores.instance.GetHighCoinScore ()) {
115 Scores.instance.SetHighCoinScore (score);
116 newHighCoinText.gameObject.SetActive (true);
117 highScoresImage.gameObject.SetActive (true);
118 audioSource.PlayOneShot (cheerClip);
119 }
120
121 highCoinScore.text = "Best Coin Score: " + Scores.instance.GetHighCoinScore ();
122 }
File name: Scores.cs
Copy
34 void GameStartedFirstTime() {
35 if(!PlayerPrefs.HasKey ("isGameStartedFirstTime")) {
36 PlayerPrefs.SetInt (BEST_SCORE, 0);
37 PlayerPrefs.SetInt (BEST_COIN_SCORE, 0);
38 PlayerPrefs.SetInt ("isGameStartedFirstTime", 0);
39
40 }
41 }
File name: Scores.cs
Copy
51 public void SetHighCoinScore (int highCoinScore) {
52 PlayerPrefs.SetInt (BEST_COIN_SCORE, highCoinScore);
53 }
File name: Scores.cs
Copy
55 public int GetHighCoinScore () {
56 return PlayerPrefs.GetInt (BEST_COIN_SCORE);
57 }
File name: GenerateGrounds.cs
Copy
32 void Start () {
33
34 groundWidth = new float[theObjectPools.Length];
35
36 for(int i = 0; i < theObjectPools.Length; i++) {
37 groundWidth [i] = theObjectPools [i].pooledObject.GetComponent
38 }
39
40 minHeight = transform.position.y;
41 maxHeight = maxHeightPoint.position.y;
42
43 coinGenerator = FindObjectOfType
44 cratesGenerator = FindObjectOfType
45 }
File name: GenerateGrounds.cs
Copy
48 void Update () {
49 if(transform.position.x < generatePoint.position.x) {
50
51 distance = Random.Range (distanceBetweenMin, distanceBetweenMax);
52
53 groundSelector = Random.Range (0, theObjectPools.Length);
54
55 heightChange = transform.position.y + Random.Range (maxHeightChange, -maxHeightChange);
56
57 if (heightChange > maxHeight) {
58 heightChange = maxHeight;
59 } else if (heightChange < minHeight) {
60 heightChange = minHeight;
61 }
62
63 transform.position = new Vector3 (transform.position.x + (groundWidth[groundSelector] / 2) + distance, heightChange, transform.position.z);
64
65 GameObject newPlatform = theObjectPools[groundSelector].GetPooledObject ();
66 newPlatform.transform.position = transform.position;
67 newPlatform.transform.rotation = transform.rotation;
68 newPlatform.SetActive (true);
69
70 if(Random.Range(0f, 100f) < randomCoins) {
71 coinGenerator.spawnCoins (new Vector3 (transform.position.x, transform.position.y + 3f, transform.position.z));
72 }
73
74 if(Random.Range(0f, 100f) < randomCrates) {
75 cratesGenerator.spawnCrates (new Vector3 (transform.position.x, transform.position.y + 1.3f, transform.position.z));
76 }
77
78 transform.position = new Vector3 (transform.position.x + (groundWidth[groundSelector] / 2) + distance, transform.position.y, transform.position.z);
79
80 }
81 }
Download file with original file name:Coin
Coin 107 lượt xem
Gõ tìm kiếm nhanh...