// Start is called before the first frame update
    void Start()
    {
        //Equip weapon on pickup
        GameManager.pickupEvent.AddListener(x => carriedWep = x.so);

        //Throw weapon away on button input.
        GameManager.discardEvent.AddListener(x =>
        {
            GameObject wep = GameObject.Instantiate(groundWep, transform.position + (transform.up * 2f), Quaternion.identity);
            wep.GetComponent <GroundedWep>().so = x;
            carriedWep = null;
        });

        //Shoot weapon on button input
        GameManager.shootEvent.AddListener(x =>
        {
            canFire = false;
            StartCoroutine(ResetFire(x.FireCooldown));


            //Multishot

            for (int i = 0; i < x.ShotAmount; i++)
            {
                Quaternion mutation = i == 0 ? Quaternion.Euler(0, 0, 0) : Quaternion.Euler(0f, 0f, UnityEngine.Random.Range(-inaccuracy, inaccuracy));
                GameObject shot     = GameObject.Instantiate(x.Shot, transform.position + (transform.up * 1f), transform.rotation);
                x.Shoot(shot.GetComponent <Rigidbody2D>(), mutation * transform.up);
            }
        });
    }
Esempio n. 2
0
    // Start is called before the first frame update
    void Start()
    {
        GameManager.EnemySemaphor++;

        GameManager.enemyPickupEvent.AddListener((obj, so) =>
        {
            if (obj == gameObject)
            {
                weapon = so;
                StopAllCoroutines();
                StartCoroutine(ShootWeapon());
            }
        });

        rb2d = GetComponent <Rigidbody2D>();
    }