Exemple #1
0
    public void Shoot()
    {
        if (projectileTimer >= projectileInterval)
        {
            projectileTimer = 0;

            GameObject projectile = objectPooler.GetNextDynamicInstance();

            float accuracy = Random.Range(-inaccuracy, inaccuracy);
            projectile.transform.up       = transform.up + (transform.right * accuracy);
            projectile.name               = objectPooler.GetPooledPrefab().name;
            projectile.transform.position = transform.position;
            projectile.SetActive(true);

            TrailResetter[] trailResetters = projectile.GetComponentsInChildren <TrailResetter>();
            foreach (TrailResetter resetter in trailResetters)
            {
                resetter.Reset();
            }

            LaserController laser = projectile.GetComponent <LaserController>();
            if (laser != null)
            {
                laser.SetStartObject(this.gameObject);
                AudioManager.instance.PlaySoundWithRandomPitch(laser.GetShotClip(), 0.5f, 1.5f);
            }

            ProjectileController proj = projectile.GetComponent <ProjectileController>();
            if (proj != null)
            {
                AudioManager.instance.PlaySoundWithRandomPitch(proj.GetShotClip(), 0.75f, 1.25f);
            }
        }
    }