Difficulty
How do I use Difficulty
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
34 | if (SystemScr.difficultyIsHard) | 1 |
78 | if (SystemScr.difficultyIsHard) | 2 |
33 | if (SystemScr.difficultyIsHard) | 3 |
32 | if (SystemScr.difficultyIsHard) | 4 |
69 | public void Difficulty_btn() | 5 |
File name: Enemy.cs
Copy
30 void Start()
31 {
32 if (enemyType != 0 && enemyType != 4)//not a boss or not a boss ring
33 {
34 if (SystemScr.difficultyIsHard)
35 lifeMax = 2;
36 else
37 lifeMax = 1;
38 }
39
40 life = lifeMax;
41 }
File name: SpawnManager.cs
Copy
42 IEnumerator SpawningRoutine()
43 {
44 yield return new WaitForSeconds(3);
45
46 while (!UIgame.scoreAchived)
47 {
48 GameObject enemy = null;
49
50 //FIRST STAGE OF SPAWNING
51 //CHOOSE ENEMY FOR SPAWN
52 int r = rand.Randomization_1(0, 10, 80, 99);
53 if (r == 0)
54 {
55 enemy = pools.GetPoolableObject("enemy_01");
56 }
57 else if (r == 1)
58 {
59 enemy = pools.GetPoolableObject("enemy_02");
60 }
61 else
62 {
63 enemy = pools.GetPoolableObject("enemy_03");
64 }
65
66 //SECOND STAGE OF SPAWNING
67 //SPAWN CHOSEN ENEMY IN RANDOM POINT ON TOP SCREEN SIDE
68 r = Random.Range(0, pointsPositions.Length);
69
70 if (enemy != null)
71 {
72 enemy.SetActive(true);
73 enemy.GetComponent
74 new Vector3(0,0,-1));
75 }
76
77 int spawnDelay;
78 if (SystemScr.difficultyIsHard)
79 spawnDelay = 1;
80 else
81 spawnDelay = Random.Range(3,5);
82
83 yield return new WaitForSeconds(spawnDelay);
84 }
85
86 //BOSS ACTIVATION
87 pools.DeleteEnemiesAndBullets();
88 CameraMotor.speedScreen = 0;
89 Camera.main.GetComponent
90 Camera.main.GetComponent
91 Camera.main.backgroundColor = Color.black;
92 GameObject.FindObjectOfType
93
94 yield return new WaitForSeconds(6);
95
96 pools.AcivateBoss();
97 }
File name: UIgame.cs
Copy
31 void Start()
32 {
33 if (SystemScr.difficultyIsHard)
34 maximumScore = 2000;
35 else
36 maximumScore = 1000;
37
38 scoreText.text = score + "/" + maximumScore;
39 scoreAchived = false;
40
41 if (SystemScr.mute)
42 muteText.text = "ON";
43 }
File name: UIstart.cs
Copy
20 void Start()
21 {
22 //setup mute text
23 if (!SystemScr.mute)
24 {
25 muteText.text = "OFF";
26 music.Play();
27 }
28 else
29 muteText.text = "ON";
30
31 //setup difficulty text
32 if (SystemScr.difficultyIsHard)
33 difficultyText.text = "HARD";
34 else
35 difficultyText.text = "EASY";
36
37 }
File name: UIstart.cs
Copy
69 public void Difficulty_btn()
70 {
71 if (!SystemScr.difficultyIsHard)
72 {
73 SystemScr.difficultyIsHard = true;
74 difficultyText.text = "HARD";
75 }
76 else
77 {
78 SystemScr.difficultyIsHard = false;
79 difficultyText.text = "EASY";
80 }
81 }
Difficulty 150 lượt xem
Gõ tìm kiếm nhanh...