Ejemplo n.º 1
0
    /// <summary>
    /// Catches every collision 2D.
    /// </summary>
    /// <param name="coll">Collision Event arguments.</param>
    private void OnCollisionEnter2D(Collision2D coll)
    {
        // When the bullet collides with another object, the bullet will explode,
        // but only if the collided object has some specific attributes.
        switch (coll.collider.tag)
        {
        case "Ground":
            groundController.DestroyGround(destructionCircle);

            updateAngle = false;
            bulletSmoke.SetActive(false);
            Destroy(gameObject);
            break;

        case "Player":
            groundController.DestroyGround(destructionCircle);

            updateAngle = false;
            bulletSmoke.SetActive(false);
            Destroy(gameObject);

            coll.gameObject.GetComponent <DamageController>().SubtractLifePoints(bulletDamage);
            break;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        timew -= Time.deltaTime;
        if (PlayerController.weapon == 2)
        {
            if (timew < 0)
            {
                groundController.DestroyGround(destructionCircle);
                Destroy(gameObject);
            }
        }
        if (updateAngle)
        {
            Vector2 dir = new Vector2(rb.velocity.x, rb.velocity.y);
            // Determinaçao do angulo do vetor velocidade
            dir.Normalize();
            float angle = Mathf.Asin(dir.y) * Mathf.Rad2Deg;
            if (dir.x < 0f)
            {
                angle = 180 - angle;
            }

            //Debug.Log("angle = " + angle);

            // Atualizanndo a rotaçao de Sprite ( GameObject que contem o Sprite Render de nossa bala )
            //de acordo com o angulo da trajetoria
            bulletSpriteTransform.localEulerAngles = new Vector3(0f, 0f, angle + 45f);
        }
    }
Ejemplo n.º 3
0
    public virtual void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.collider.tag == "Ground")
        {
            groundController.DestroyGround(destructionCircle);
            Explode();
            MakeSoundExplosion();
//			Destroy (this.gameObject);
//			Instantiate (boom);
//			boom.Play ();
        }
        else if (coll.collider.tag == "Tank" || coll.collider.tag == "Hitable")
        {
//			Destroy (gameObject);
            Explode();
            MakeSoundExplosion();
//			Instantiate (boom);
//			boom.Play ();

            //health.TakeDamage(20);
            if (coll.gameObject.GetComponent <Player_Health> () != null)
            {
                //					print ("folgender Tank wurde getroffen: " + coll.gameObject);
                p_health = coll.gameObject.GetComponent <Player_Health> ();
                p_health.SetHealth(10f);
            }
        }
    }
Ejemplo n.º 4
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.collider.tag == "Ground")
     {
         groundController.DestroyGround(destructionCircle);
         Destroy(gameObject);
     }
 }
Ejemplo n.º 5
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.collider.tag == "Ground")
     {
         updateAngle = false;
         bulletSmoke.SetActive(false);
         groundController.DestroyGround(destructionCircle);
         Destroy(gameObject);
     }
 }
Ejemplo n.º 6
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     // Quando a bala colide com outro corpo que nao seja o Player ela
     //não mais atualiza a rotação baseado na trajetória
     // e o efeito de partícula do rastro da bala é desativado
     if (coll.collider.tag == "Ground")
     {
         updateAngle = false;
         bulletSmoke.SetActive(false);
         groundController.DestroyGround(destructionCircle);
         Destroy(gameObject);
     }
 }
 public void GiveDemage()
 {
     Collider2D[] objToDamage = Physics2D.OverlapCircleAll(transform.position, destructionArea.radius);
     foreach (Collider2D obj in objToDamage)
     {
         var demagable = obj.GetComponent <IDamageable <float> >();
         if (demagable != null)
         {
             demagable.Damage(weapon.damage);
             Debug.Log(obj.name + weapon.damage);
         }
     }
     groundController.DestroyGround(destructionArea);
     Destroy(gameObject);
 }
Ejemplo n.º 8
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     if (coll.collider.tag == "Ground" && !isDestroyed)
     {
         updateAngle = false;
         bulletSmoke.SetActive(false);
         groundController.DestroyGround(destructionCircle);
         if (!isDestroyed)
         {
             explosionEffectObject = Instantiate(explosionEffectPrefab, transform.position, Quaternion.identity);
             Invoke("RemoveEffectTrigger", 0.2f);
             DestroySelf(true);
             SFX.PlayOneShot(boomSFX);
         }
     }
     else if (coll.collider.CompareTag("BombBracket") && !isDestroyed)
     {
         updateAngle = false;
         bulletSmoke.SetActive(false);
         Invoke("RemoveEffectTrigger", 0.2f);
         DestroySelf(true);
         SFX.PlayOneShot(boomSFX);
     }
 }