Ejemplo n.º 1
0
    //private void OnCollisionEnter2D(Collision2D collision)
    //{
    // MOVED TO SERVER

    /*
     * if (collision.rigidbody.tag == "Enemy")
     * {
     *  triggeringEnemy = collision.rigidbody.gameObject;
     *  triggeringEnemy.GetComponent<Enemy>().health -= damage;
     *  Destroy(this.gameObject);
     * }
     *
     * if (collision.rigidbody.tag == "Asteroid")
     * {
     *  GameObject triggeringAst = collision.rigidbody.gameObject;
     *  triggeringAst.GetComponent<Asteroid>().InflictDamage(damage);
     *  Destroy(this.gameObject);
     * }
     * //	}
     *
     *  private void OnTriggerEnter(Collider other)
     *  {
     *      if (other.tag == "Enemy")
     *      {
     *          triggeringEnemy = other.gameObject;
     *          triggeringEnemy.GetComponent<Enemy>().health -= damage;
     *          Destroy(this.gameObject);
     *      }
     *
     *      if (other.tag == "Asteroid")
     *      {
     *          GameObject triggeringAst = other.gameObject;
     *          triggeringAst.GetComponent<Asteroid>().health -= damage;
     *          Destroy(this.gameObject);
     *      }
     *  }*/

    //private void OnCollisionEnter(Collision collision)
    //{


    //    // check if other game object is an asteroid
    //    Asteroid ast = collision.gameObject.GetComponent<Asteroid>();
    //    Asteroid ast2 = collision.transform.GetComponent<Asteroid>();
    //    //        Asteroid ast3 = collision.rigidbody.GetComponent<Asteroid>();
    //    // Asteroid ast4 = collision.
    //    if (ast != null || ast2 != null || ast2 != null)
    //    {
    //        Vector3 pos = this.GetComponent<Collider>().transform.position;
    //        Debug.Log("collide at " + pos.ToString());
    //        fxController.PlasmaGunImpact(collision.transform.position);
    //        // todoj tell server we destroyed the asteroid
    //        ast.InflictDamage(damage);

    //        Destroy(this);
    //    }


    //}


    private void OnTriggerEnter(Collider other)
    {
        Vector3 pos = this.GetComponent <Collider>().transform.position;

        Debug.Log("collide at " + pos.ToString());
        fxController.PlasmaGunImpact(other.transform.position);
        ApplyGridForce(5f, 3f);
        ParticleSystem[] psystems = GetComponentsInChildren <ParticleSystem>();
        foreach (ParticleSystem ps in psystems)
        {
            Destroy(ps);
        }
        // check if other game object is an asteroid
        Asteroid ast = other.gameObject.GetComponent <Asteroid>();

        if (ast != null)
        {
            // todoj tell server we destroyed the asteroid
            ast.InflictDamage(damage);
        }

        Destroy(this);
    }