[SerializeField] protected Transform shootingPoint; //子弹生成点的Transform

        public override bool Shoot(Vector2 direction, ShootingBaseStats baseStats)
        {
            if (!isReloading && Time.time - lastShootingTime > 1 / (weaponData.shootingSpeed + baseStats.baseSpeed))
            {
                Projectile projectile = GetAProjectile(baseStats);
                projectile.Launch(shootingPoint.position, direction);

                //后坐力
                ApplyRecoilForce();

                if (effectName != null)
                {
                    EffectPool.instance.PlayEffect(effectName, shootingPoint.position, direction);
                }

                lastShootingTime = Time.time;
                projectileLeft--;
                if (projectileLeft <= 0)
                {
                    Reload();
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override bool Shoot(Vector2 direction, ShootingBaseStats baseStats)
        {
            if (!isReloading)
            {
                thisFrameIsShooting = true;

                if (isCharging)
                {
                    if (Time.time - shootingStartTime >= chargeTime)
                    {
                        //发射子弹
                        Projectile projectile = GetAProjectile(baseStats);
                        projectile.Launch(shootingPoint.position, direction);

                        //后坐力
                        transform.position = Vector3.zero;
                        ApplyRecoilForce();

                        //特效
                        if (effectName != null)
                        {
                            EffectPool.instance.PlayEffect(effectName, shootingPoint.position, direction);
                        }

                        //换弹逻辑
                        lastShootingTime = Time.time;
                        projectileLeft--;
                        if (projectileLeft <= 0)
                        {
                            Reload();
                        }

                        //刷新蓄力
                        isCharging = false;

                        return(true);
                    }
                    else
                    {
                        //Debug.Log("isCharging");
                        float xAmount = Random.Range(-1f, 1f) * 0.05f;
                        float yAmount = Random.Range(-1f, 1f) * 0.05f;
                        transform.localPosition = new Vector3(xAmount, yAmount, 0);
                    }
                }
            }

            return(false);
        }
        protected Projectile GetAProjectile(ShootingBaseStats baseStats)
        {
            //获取子弹
            Projectile projectile = ProjectilePool.instance.SpawnAProjectile(weaponData.projectilePoolName);

            //射子弹
            if (transform.parent.gameObject.layer == 9)
            {
                projectile.layermaskToHit = 1 << 8 | 1 << 10 | 1 << 12 | 1 << 13;
            }
            else
            {
                projectile.layermaskToHit = 1 << 9 | 1 << 8;
            }
            projectile.damage.damage         = weaponData.attack + baseStats.baseAttack;
            projectile.damage.knockbackForce = weaponData.knockbackForce;
            projectile.speed    = weaponData.projectileSpeed + baseStats.baseProjectileSpeed;
            projectile.range    = weaponData.range + baseStats.baseRange;
            projectile.lastTime = weaponData.lastTime;

            return(projectile);
        }
Exemple #4
0
        public override bool Shoot(Vector2 direction, ShootingBaseStats baseStats)
        {
            if (!isReloading && Time.time - lastShootingTime > 1 / (weaponData.shootingSpeed + baseStats.baseSpeed))
            {
                for (int i = 0; i < shootingPoints.Count; i++)
                {
                    Projectile projectile = GetAProjectile(baseStats);
                    //float angle = shootingPoints[i].eulerAngles.z * Mathf.Deg2Rad;
                    //Vector2 directionVec = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));

                    Vector2 shootdir = shootingPoints[i].localRotation * direction;

                    projectile.Launch(shootingPoints[i].position, shootdir);

                    if (effectName != null)
                    {
                        EffectPool.instance.PlayEffect(effectName, shootingPoints[i].position, shootdir);
                    }
                }

                //后坐力
                ApplyRecoilForce();

                lastShootingTime = Time.time;
                projectileLeft--;
                if (projectileLeft <= 0)
                {
                    Reload();
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
 abstract public void SpawnProjectile(Vector2 direction, ShootingBaseStats baseStats);
 /// <summary>
 /// 朝指定方向射出子弹
 /// </summary>
 /// <param name="direction">方向</param>
 /// <param name="baseStats">影响最终输出的人物参数</param>
 /// <returns>是否射出子弹</returns>
 abstract public bool Shoot(Vector2 direction, ShootingBaseStats baseStats);