Ejemplo n.º 1
0
    void Shoot()
    {
        Vector2 mousePosition = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);

        Vector2 firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y);

        RaycastHit2D hit = Physics2D.Raycast(firePointPosition, mousePosition - firePointPosition, 100, whatToHit);

        StartCoroutine("Effect");

        Debug.DrawLine(firePointPosition, (mousePosition - firePointPosition) * 100, Color.cyan);

        if (hit.collider != null)
        {
            Debug.DrawLine(firePointPosition, hit.point, Color.red);

            enemy enemy = hit.collider.GetComponent <enemy>();

            if (enemy != null)
            {
                enemy.DamageEnemy(Damage);
                Debug.Log("We hit " + hit.collider.name + " and did " + Damage + " damage.");
            }

            //if (hit.collider.tag == "Enemy")
            //{
            //    Debug.Log("shooting enemy");
            //}
        }

        //if (hit.rigidbody)
        //{
        //    if (hit.rigidbody.tag == "Enemy")
        //    {
        //        Debug.Log("shooting enemy");
        //    }
        //}
    }