Пример #1
0
    // Spawn a missile with degree offset of angleDiffDegr
    public void spawnMissileAtDegreeOffset(float angleDiffDegr, bool seekingEnabled)
    {
        float angleDiffRad = angleDiffDegr * Mathf.Deg2Rad;

        float a = transform.eulerAngles.z * Mathf.Deg2Rad;

        a += angleDiffRad;

        Vector3 offset = new Vector3(Mathf.Cos(a), Mathf.Sin(a), 0) * _offset;

        // Spawn the missile
        Vector3 pos = transform.position + offset;

        GameObject missile = Instantiate(_missile, pos, transform.rotation);

        activeMissiles.Add(missile);

        linear_travel   linTrav = missile.GetComponentInChildren <linear_travel> ();
        seeking_missile seeking = missile.GetComponentInChildren <seeking_missile> ();

        //Vector2 playerVelo = transform.root.gameObject.GetComponentInChildren<PlayerMove> ().velo;

        if (seekingEnabled)
        {
            linTrav.enabled = false;
            seeking.enabled = true;

            //seeking.setVelo (playerVelo);
            Vector2 direction = pos - transform.position;
            float   speed     = linTrav.getBaseSpeed;
            seeking.setVelo(direction, speed * 10);
        }
        else
        {
            linTrav.enabled = true;
            seeking.enabled = false;

            //linTrav.setSpeed(playerVelo.magnitude);
        }

        // Set the correct rotation
        missile.transform.Rotate(new Vector3(0, 0, angleDiffDegr));

        // Set its explosion settings
        BulletScript BS = missile.GetComponentInChildren <BulletScript>();

        BS.setExploSettings(exploRadiusMult, _explosionDamage);
    }
Пример #2
0
    // Destroy all missiles from active_missiles static list
    public static void destroyAllMissiles()
    {
        if (active_missiles == null)
        {
            return;
        }

        while (active_missiles.Count > 0)
        {
            seeking_missile missile = active_missiles [0];
            BulletScript    BS;
            if (missile && (BS = missile.GetComponent <BulletScript>()))
            {
                BS.destroyBullet();
            }
            active_missiles.RemoveAt(0);
        }
    }