Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == photonTag)
        {
            Photon photon = collision.transform.GetComponent <Photon>();

            points = photon.curEnergy;

            photon.InstantDead();
            if (targetStatus != null && collision.gameObject.GetComponent <Photon>().shooter == shooter)
            {
                //Debug.Log("Hit!");
                //Debug.Log("in");

                //Debug.Log(photon.transform.position);

                //Debug.Log(photon.GetComponent<Rigidbody2D>().velocity);

                RaycastHit2D   hit = Physics2D.Raycast(photon.transform.position, photon.GetComponent <Rigidbody2D>().velocity, 1f);
                ParticleSystem newPs;
                if (hit == true)
                {
                    newPs = Instantiate(ps, (Vector3)hit.point, Quaternion.Euler(0, 0, 0), transform);
                    Destroy(newPs, 1);
                    //Debug.Log("here??");
                    TryPlayHitSound();
                }
                else
                {
                    //hit = Physics2D.Raycast(photon.transform.position, -photon.GetComponent<Rigidbody2D>().velocity, 1f);
                    //if(hit == true)
                    //{
                    //    newPs = Instantiate(ps, (Vector3)hit.point, Quaternion.Euler(0, 0, 0), transform);
                    //    Destroy(newPs, 1);
                    //    //Debug.Log("here?????");
                    //    TryPlayHitSound();
                    //}

                    newPs = Instantiate(ps, collision.transform.position, Quaternion.Euler(0, 0, 0), transform);
                    Destroy(newPs, 1);
                    //Debug.Log("here?????");
                    TryPlayHitSound();
                }
                //Debug.Log("damn");
                selfStatus.MinusHealth(points);
                //targetStatus.addScore(1);
            }
        }
    }