Ejemplo n.º 1
0
    public bool Fire()
    {
        if (gameObject.activeSelf)
        {
            if (timer.Next(1 / fireRate))
            {
                float      shipSpeed   = ship.GetComponent <Rigidbody2D>().velocity.magnitude;
                GameObject shellObject = Instantiate(projectile, gameObject.transform.position, transform.rotation);
                shellObject.transform.Translate(fireLocation);

                Shell shell = shellObject.AddComponent <Shell>();
                shell.source        = ship;
                shell.speed         = shell.transform.up * (projectileSpeed + shipSpeed);
                shell.movementLogic = delegate(Shell s, Rigidbody2D rb) { ShellMovementLogic(s, rb); };

                //shell.transform.Translate(shell.transform.up * shipSpeed * Time.deltaTime);

                if (hitscan)
                {
                    if (shell.GetComponent <Collider2D>())
                    {
                        Destroy(shell.GetComponent <Collider2D>());
                    }
                    HitscanShot(shell);
                }
                else
                {
                    shell.collisionLogic = delegate(Shell s, GameObject collided, bool isShip, Collision2D collision) { ShellCollisionLogic(s, collided, isShip, collision); };
                }

                if (particleEffect)
                {
                    particleEffect.Emit(UnityEngine.Random.Range(10, 20));
                }

                if (fireSound)
                {
                    AudioManager.Play(fireSound, transform.position, UnityEngine.Random.Range(0.25f, 0.5f));
                }

                return(true);
            }
        }

        return(false);
    }