示例#1
0
 void OnCollisionEnter2D(Collision2D theCollision)
 {
     //Проверяем коллизию с объектом типа «лазер»
     if (theCollision.gameObject.name.Contains("laser") || theCollision.gameObject.name.Contains("playerShip"))
     {
         if (theCollision.gameObject.name.Contains("playerShip"))
         {
             health -= 100;
         }
         laserScript laser = theCollision.gameObject.GetComponent("laserScript") as laserScript;
         health = health - laser.damage;
         Destroy(theCollision.gameObject);
         // Воспроизвести звук попадания выстрела
         GetComponent <AudioSource>().PlayOneShot(hitSound);
     }
     if (health <= 0)
     {
         // Срабатывает при уничтожении объекта
         if (explosion)
         {
             GameObject exploder = ((Transform)Instantiate(explosion, this.transform.position, this.transform.rotation)).gameObject;
             Destroy(exploder, 2.0f);
         }
         Destroy(this.gameObject);
         GameController controller = GameObject.FindGameObjectWithTag("GameController").GetComponent("GameController") as GameController;
         controller.KilledEnemy();
         controller.IncreaseScore(5);
     }
 }
示例#2
0
 // Use this for initialization
 void Start()
 {
     qucikcounter = 0;
     //GenerateRandomChallenge();
     leftlaser = PlayerPrefs.GetInt("LASERCOUNT");
     lsr       = FindObjectOfType <laserScript> ();
 }
 void OnCollisionEnter2D(Collision2D theCollision)
 {
     if (theCollision.gameObject.name.Contains("blast"))
     {
         laserScript laser = theCollision.gameObject.GetComponent("laserScript") as laserScript;
         health = health - laser.damage;
         Destroy(theCollision.gameObject);
     }
     //Проверяем коллизию с объектом типа «enemy» или падение здоровья к нулю
     if (theCollision.gameObject.name.Contains("enemy") || health <= 0)
     {
         Destroy(theCollision.gameObject);
         // Срабатывает при уничтожении объекта
         if (explosion)
         {
             GameObject exploder = ((Transform)Instantiate(explosion, this.transform.position, this.transform.rotation)).gameObject;
             Destroy(exploder, 2.0f);
         }
         Destroy(this.gameObject);
     }
 }