Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && _weaponSelected != null) {
            AudioSource.PlayClipAtPoint(fire, Vector3.up);
        }
        if (Input.GetKeyDown(KeyCode.E) && _weaponSelected == null) {
            _colSelected = Physics2D.OverlapPoint(transform.position);
            if (_colSelected && _colSelected.tag == "weapon") {
                AudioSource.PlayClipAtPoint(reload, Vector3.up);
                _weaponSelected = _colSelected.gameObject.GetComponent<generateWeapon>();
                anim = _weaponSelected.GetComponent<Animator>();
                _weapon = _weaponSelected.weapon.GetComponent<weapons>();
                attachToBody.GetComponent<SpriteRenderer>().sprite = _weapon.attachToBody;
                weapon2 = weapon.GetComponent<weapon>();
                bullet_prefab = weapon.GetComponent<weapon>().bullet_prefab;
                bullet_prefab.GetComponent<SpriteRenderer>().sprite = weapon2.bullets[_weaponSelected.i];

                _weaponSelected.transform.localScale = Vector3.zero;

                anim.SetBool("isTake", true);
                anim.SetBool("isDrop", false);

            }
        }

        if (Input.GetMouseButtonDown (1) && _weaponSelected != null) {
            anim.SetBool("isTake", false);
            anim.SetBool("isDrop", true);
            _weaponSelected.transform.position = transform.position;
            attachToBody.GetComponent<SpriteRenderer>().sprite = null;

            _weaponSelected = null;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && _weaponSelected != null)
        {
            AudioSource.PlayClipAtPoint(fire, Vector3.up);
        }
        if (Input.GetKeyDown(KeyCode.E) && _weaponSelected == null)
        {
            _colSelected = Physics2D.OverlapPoint(transform.position);
            if (_colSelected && _colSelected.tag == "weapon")
            {
                AudioSource.PlayClipAtPoint(reload, Vector3.up);
                _weaponSelected = _colSelected.gameObject.GetComponent <generateWeapon>();
                anim            = _weaponSelected.GetComponent <Animator>();
                _weapon         = _weaponSelected.weapon.GetComponent <weapons>();
                attachToBody.GetComponent <SpriteRenderer>().sprite = _weapon.attachToBody;
                weapon2       = weapon.GetComponent <weapon>();
                bullet_prefab = weapon.GetComponent <weapon>().bullet_prefab;
                bullet_prefab.GetComponent <SpriteRenderer>().sprite = weapon2.bullets[_weaponSelected.i];

                _weaponSelected.transform.localScale = Vector3.zero;

                anim.SetBool("isTake", true);
                anim.SetBool("isDrop", false);
            }
        }

        if (Input.GetMouseButtonDown(1) && _weaponSelected != null)
        {
            anim.SetBool("isTake", false);
            anim.SetBool("isDrop", true);
            _weaponSelected.transform.position = transform.position;
            attachToBody.GetComponent <SpriteRenderer>().sprite = null;

            _weaponSelected = null;
        }
    }