コード例 #1
0
    //void TurnCorrection(Vector3 mousePos)
    //{
    //    //find distances and angles
    //    d = Vector2.Distance(new Vector2(gunpoint.transform.position.x, mousePos.y), new Vector2(turretTransform.position.x, turretTransform.position.y));
    //    x = Vector2.Distance(new Vector2(turretTransform.position.x, turretTransform.position.y), new Vector2(weaponTransform.position.x, weaponTransform.position.y));
    //    weaponAngle = weaponTransform.localEulerAngles.z;
    //    weaponAngle = weaponAngle * Mathf.Deg2Rad;
    //    y = Mathf.Abs(Mathf.Cos(weaponAngle) * x);
    //    b = Mathf.Rad2Deg * Mathf.Acos(y / d);
    //    a = Mathf.Rad2Deg * Mathf.Acos(y / x);
    //    //turn turret towards target
    //    turretTransform.up = targetTransform.position - turretTransform.position;
    //    //adjust for gun angle
    //    if (weaponTransform.localEulerAngles.z < 180)
    //        turretTransform.Rotate(Vector3.forward, 90 - b - a);
    //    else
    //        turretTransform.Rotate(Vector3.forward, 90 - b + a);
    //    //Please leave this comment in the code. This code was made by
    //    //http://gamedev.stackexchange.com/users/93538/john-hamilton a.k.a. CrazyIvanTR.
    //    //This code is provided as is, with no guarantees. It has worked in local tests on Unity 5.5.0f3.
    //}


    void ShootBullet(Vector3 mousePos)
    {
        int currAmmo = gunScript.ShootClip(true);
        //if (gunScript && gunScript.ammoCurrent - 1 >= 0) // no dispara si no tiene balas
        //{
        //if (currAmmo >= 0 && gunScript.currentGunStats.shootSfx)
        //    //this.sfxPlayer.PlayOneShot(gunScript.currentGunStats.shootSfx);
        //    SoundManager.instance.PlayEffect(gunScript.currentGunStats.shootSfx);

        //else if (gunScript.noClipSfx)
        //    //this.sfxPlayer.PlayOneShot(gunScript.noClipSfx);
        //    SoundManager.instance.PlayEffect(gunScript.noClipSfx);

        //bajo la municion
        //HudController.current.UpdateRoundsUI(gunScript.ammoCurrent, gunScript.ammoMax);
        //}
        //else
        //{
        //this.sfxPlayer.PlayOneShot(gunScript.sfxNoClip);
        //HudController.current.UpdateRoundsUI(0, 0); // no bullet
        //return;
        //}

        var bullet_go = Instantiate(bulletPrefab, gunpoint.transform.position, Quaternion.identity);
        var bullet    = bullet_go.GetComponent <Bullet>();

        var directionVector = (mousePos - gunpoint.transform.position).normalized;

        bullet.forceToAppend     = directionVector;
        bullet.parentToIgnoreCol = this.GetComponent <Collider2D>();


        this.currentCooldown = 0; // Reseteo el cd
    }
コード例 #2
0
    void ShootBullet(Vector3 targetPos)
    {
        int currAmmo = gunScript.ShootClip(true);

        if (currAmmo >= 0 && gunScript.currentGunStats.shootSfx)
        {
            this.sfxPlayer.PlayOneShot(gunScript.currentGunStats.shootSfx);
            var bullet_go = Instantiate(bulletPrefab, gunpoint.transform.position, Quaternion.identity);
            var bullet    = bullet_go.GetComponent <Bullet>();

            var directionVector = (targetPos - gunpoint.transform.position).normalized;

            bullet.forceToAppend     = directionVector;
            bullet.parentToIgnoreCol = this.GetComponent <Collider2D>(); // paso la hitbox para ignorar

            print("bullet heading " + directionVector);
            this.currentCooldown = gunCooldown; //reset cooldown

            this.gunScript.ShootClip(false);
        }
        else if (gunScript.noClipSfx)
        {
            print("out of bullets " + this.name);
            //cambio de rutina al no tener balas
            this.gameObject.GetComponent <FetchAndAttack>().enabled = true;

            AlteredState a_state;
            TryGetComponent(out a_state);

            this.sfxPlayer.PlayOneShot(gunScript.noClipSfx);
            this.gunScript.SetToMelee();
            gunHolder.sprite = null;

            if (a_state)
            {
                a_state.enabled = true;
            }

            this.enabled = false;
        }
    }