Boss
How do I use Boss
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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
26 transform.GetComponent
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: BossHealth.cs
Copy
44 void BossDestroyed(){
45 Destroy (gameObject);
46 GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent
47 GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent
48 if(GameController.instance != null && MusicController.instance != null){
49 if(GameController.instance.isMusicOn){
50 MusicController.instance.audioSource.PlayOneShot (MusicController.instance.bossExplode);
51 }
52 }
53 Instantiate (explode, transform.position, Quaternion.identity);
54 for (int i = 0; i < 5; i++) {
55 Instantiate (coin, transform.position, Quaternion.identity);
56 }
57 }
File name: GameBoundary.cs
Copy
17 void OnTriggerEnter2D(Collider2D collider){
18 if(collider.CompareTag("Player Bullet") || collider.CompareTag("Enemy") || collider.CompareTag("Coin") || collider.CompareTag("Boss Bullet")){
19 Destroy (collider.gameObject);
20 }
21
22 }
File name: EnemySpawner.cs
Copy
82 void CheckedEnemies(){
83 if(!active){
84 if (GameObject.FindGameObjectWithTag("Enemy") == null) {
85 if(!isBossReady){
86 isBossReady = true;
87 GameplayController.instance.ShowWarning();
88 }
89 }
90 }
91 }
File name: EnemySpawner.cs
Copy
94 public void SpawnBoss(){
95 Instantiate (boss[0], new Vector3 (0, maxTop + 3, 0), Quaternion.Euler(0, 0, 180));
96 }
File name: EnemySpawner.cs
Copy
98 public void InitializeVariables(){
99 count = maxCount;
100 time = 0f;
101 active = true;
102 isBossReady = false;
103 }
File name: GameplayController.cs
Copy
125 void ClearAllEnemies(){
126 GameObject[] enemies = GameObject.FindGameObjectsWithTag ("Enemy");
127 GameObject[] bossbullets = GameObject.FindGameObjectsWithTag ("Boss Bullet");
128 GameObject[] coins = GameObject.FindGameObjectsWithTag ("Coin");
129 GameObject boss = GameObject.FindGameObjectWithTag ("Boss");
130
131 if(boss != null){
132 Destroy (boss);
133 }
134
135 if(enemies != null){
136 foreach (GameObject enemy in enemies) {
137 Destroy (enemy);
138 }
139 }
140
141 if(bossbullets != null){
142 foreach (GameObject bossBullet in bossbullets) {
143 Destroy (bossBullet);
144 }
145 }
146
147 if(coins != null){
148 foreach (GameObject coin in coins) {
149 Destroy (coin);
150 }
151 }
152
153 }
Download file with original file name:Boss
Boss 140 lượt xem
Gõ tìm kiếm nhanh...