Bonus









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

Featured Snippets


File name: Enemy.cs Copy
99     public void Die()
100     {
101         GameObject bonus = pools.GetPoolableObject("bonus");
102         if (bonus != null)
103         {
104             bonus.SetActive(true);
105             bonus.GetComponent().Activation(transform.position);
106         }
107         if (enemyType == 4)
108             uiForScore.Win();
109         else
110             uiForScore.IncreaseScore(20);
111
112         transform.gameObject.SetActive(false);
113     }
File name: Pools.cs Copy
26     void Start()
27     {
28         enemies_01 = CreateObjects(prefabEnemy_01, 1);
29         enemies_02 = CreateObjects(prefabEnemy_02, 6);
30         enemies_03 = CreateObjects(prefabEnemy_03, 4);
31         bonuses = CreateObjects(prefabBonus, 8);
32         bulletsPlayer = CreateObjects(prefabBulletPlayer, 10);
33         bulletsEnemy = CreateObjects(prefabBulletEnemy, 700);
34     }
File name: Pools.cs Copy
50     public GameObject GetPoolableObject(string objName)
51     {
52         GameObject returningObj = null;
53         GameObject[] allObjects = null;
54
55         switch (objName)
56         {
57             case "p_bullet": allObjects = bulletsPlayer; break;
58             case "e_bullet": allObjects = bulletsEnemy; break;
59             case "enemy_01": allObjects = enemies_01; break;
60             case "enemy_02": allObjects = enemies_02; break;
61             case "enemy_03": allObjects = enemies_03; break;
62             case "bonus": allObjects = bonuses; break;
63         }
64
65         for (int i = 0; i < allObjects.Length; i++)
66         {
67             if (!allObjects[i].activeInHierarchy)
68             {
69                 returningObj = allObjects[i];
70             }
71         }
72
73         return returningObj;
74     }
File name: Bonus.cs Copy
18     void RandomizeBonus()
19     {
20         int r = random.Randomization_1(0, 10, 50, 80, 99);
21         thisBonus = (BonusesEnum)r;
22         rend.sharedMaterial = materials[r];
23     }
File name: Bonus.cs Copy
25     public void Activation(Vector3 revealPosition)
26     {
27         transform.position = revealPosition;
28         RandomizeBonus();
29     }
File name: Bonus.cs Copy
31     void OnTriggerExit(Collider col)
32     {
33         if (col.tag == "SpawnBorders")
34         {
35             BonusIsOff();
36         }
37     }
File name: Bonus.cs Copy
39     void BonusIsOff()
40     {
41         transform.gameObject.SetActive(false);
42     }
File name: PlayerControl.cs Copy
100     void OnTriggerEnter(Collider col)
101     {
102         if (col.tag == "Enemy" || col.tag == "Danger")
103         {
104             GetDamage();
105         }
106         if (col.tag == "Bonus")
107         {
108             sounds.PlaySoundsPlayer(3);
109             GetBonusEffect(col.GetComponent().thisBonus);
110             ui.ShowLives(lifeCurrent);
111             col.gameObject.SetActive(false);
112         }
113     }
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: PlayerControl.cs Copy
160     public void IncreaseScoreByBonus(int score = 100)
161     {
162         ui.IncreaseScore(score);
163     }

Download file with original file name:Bonus

Bonus 123 lượt xem

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