Ejemplo n.º 1
0
  } // end updatat

  /** OnCollisionEnter does:
   * When a bullet hits the collision it takes one enemy out of the enemiesLeft 
   * and destroies itself
   */
  private void OnCollisionEnter(Collision collision)
  {
    //Debug.Log("was hit");

    GameControllerScript controllerScript = gameController.GetComponent<GameControllerScript>();
    if ( collision.collider.tag == "Bullet")
    {
      //Debug.Log("enemy destroy onCollisionEnter");

      if (!source.isPlaying)
      {
        source.PlayOneShot(hitSound, 1);

      }
      controllerScript.enemiesLeft--;
      Destroy(gameObject, 30F);
      Destroy(playerCollider);
      enemyAnimator.SetTrigger("Dying");
      Enemy_Smart enemyScript = gameObject.GetComponent<Enemy_Smart>();
      Destroy(enemyScript);
      Lazer_Eye_Shooting lazerScript = lazerEyeScriptObj.gameObject.GetComponent<Lazer_Eye_Shooting>();
      Destroy(lazerScript);




    } // end if bullet

  } // end OnCollisionEnter
    // Update is called once per frame
    private void Update()
    {
        Enemy_Smart SelfMainScript = selfMain.GetComponent <Enemy_Smart>();

        if (SelfMainScript.shootLazer)
        {
            if (lastFire <= Time.time)
            {
                SelfMainScript.enemyAnimator.SetTrigger("Shoot_Lazer");
                lastFire = Time.time + 2F;
                Fire();

                if (!source.isPlaying)
                {
                    source.PlayOneShot(shootSound, 1);
                }
            }
        }

        else
        {
        }
    }