예제 #1
0
    //public void Shoot()
    //{
    //    GetComponent<Animator>().SetBool("shoot", true);
    //    Instantiate(bullet, firepoint.position, firepoint.rotation);
    //}
    public void Shoot()
    {
        RaycastHit2D hitinfo = Physics2D.Raycast(firepoint.position, firepoint.right);

        if (hitinfo)
        {
            Enemy   enemy   = hitinfo.transform.GetComponent <Enemy>();
            Octopus octopus = hitinfo.transform.GetComponent <Octopus>();
            if (enemy != null)
            {
                enemy.Takedamage(damage);
            }
            else if (octopus != null)
            {
                octopus.Takedamage(damage);
            }
            else if (hitinfo.transform.gameObject.tag == "pickups")
            {
                hitinfo.transform.gameObject.GetComponent <Pickup>().destroystone(damage);
                //Debug.Log(status);
            }
            Instantiate(shootani, hitinfo.point, Quaternion.identity);//Quaternion.identity:fancy way of showing no rotation
        }

        GetComponent <Animator>().SetBool("shoot", true);
        line.SetPosition(0, firepoint.position);
        line.SetPosition(1, hitinfo.point);
        line.enabled = true;
    }
예제 #2
0
    //private void OnTriggerEnter2D(Collider2D collision)
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Enemy   enemy   = collision.transform.GetComponent <Enemy>();
        Octopus octopus = collision.transform.GetComponent <Octopus>();

        if (enemy != null)
        {
            enemy.Takedamage(damage);
        }
        else if (octopus != null)
        {
            octopus.Takedamage(damage);
        }
        else if (collision.gameObject.tag == "pickup")
        {
            collision.transform.gameObject.GetComponent <Pickup>().destroystone(damage);
        }
        Instantiate(shootani, transform.position, transform.rotation);
        Destroy(gameObject);
    }