コード例 #1
0
 //trigger detection for enemy ships and coins.
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "UpgradeCoin")
     {
         //Debug.Log ("Trigger Collision: " + col.tag);
         CoinValue value = col.gameObject.GetComponent <CoinValue> ();
         PlayerStatsManager.SetPlayerScore(value.GetCoinValue());
         value.PassUpgradeValue();
         Destroy(col.gameObject);
     }
     if (col.tag == "Enemy Ship" || col.tag == "EliteEnemyShip")
     {
         PlayerStatsManager.SetPlayerHealth(-enemyCollisionDamage);
         EnemyAI collide = col.gameObject.GetComponent <EnemyAI> ();
         if (col.tag == "EliteEnemyShip")
         {
             collide.SetDamage(5f);
         }
         else
         {
             collide.SetDamage(100f);
         }
         hurtSound.Play();
     }
 }
コード例 #2
0
 //Spawn player on death if there are lives left.
 private void Spawn()
 {
     if (PlayerStatsManager.GetPlayerLives() > 0f)
     {
         Vector2 startPos = new Vector2(-5.3f, 0f);
         transform.position = startPos;
         PlayerStatsManager.SetPlayerHealth(maxHealth);
         PlayerStatsManager.SetUpgradePoints(-10f);
     }
     else
     {
         PlayerStatsManager.SetCanSpawn(false);
         SceneManager.LoadScene("game_over");
         Destroy(gameObject);
     }
 }
コード例 #3
0
 // sends damage to player stat manager. Positive number decreases health.
 public void SetDamage(float damage)
 {
     PlayerStatsManager.SetPlayerHealth(damage * -1f);
 }