Пример #1
0
    IEnumerator GenerateTrashDebris(int level)
    {
        List <Debris> trash = new List <Debris>();

        if (trash.Count > 0)
        {
            throw new UnityException("Trash was not empty");
        }

        Debris.trash = new List <Debris>();
        for (int i = 0; i < trash_debris_num[level]; i++)
        {
            Debris d = Instantiate(debris_prefab);
            d.persistent = false;

            trash.Add(d);
        }

        Debris.trash.AddRange(trash);

        foreach (Debris d in trash)
        {
            d.Initialize();
            yield return(new WaitForSeconds(generate_delay[level] / 2f));;
            d.Fly();
        }
        trash_routine = null;
    }
Пример #2
0
    private void SpawnDebrisTowardPlayer()
    {
        // Make sure that at least ONE debris goes toward the player
        Debris d          = GameObject.Instantiate(Debris, transform.position + (Vector3)Random.insideUnitCircle, Quaternion.identity).GetComponent <Debris>();
        float  dMass      = .2f;
        float  dMoveSpeed = RandomHelper.RandomDebrisMovementSpeed();
        // Vector2 dVelocity = new Vector2((debrisSpawnDirection.x + Random.Range(-2f, 2f)) * dMoveSpeed, (debrisSpawnDirection.y + Random.Range(-2f, 2f)) * dMoveSpeed);
        Vector2 direction = (GameObject.FindGameObjectWithTag("Player").transform.position - transform.position).normalized;
        Vector2 dVelocity = direction * dMoveSpeed;

        d.Initialize(dMass, dVelocity);
    }
Пример #3
0
    public void DestroyAstroid(Vector3 debrisSpawnDirection)
    {
        // BUG: Something is going on with Debris not being defined for some Asteroids, Just gonna turn it off
        if (Debris == null)
        {
            return;
        }
        // Spawn Debris
        for (int i = 0; i < Random.Range(0f, 1f); i++)
        {
            Debris  d          = GameObject.Instantiate(Debris, transform.position + (Vector3)Random.insideUnitCircle, Quaternion.identity).GetComponent <Debris>();
            float   dMass      = .2f;
            float   dMoveSpeed = RandomHelper.RandomDebrisMovementSpeed();
            Vector2 dVelocity  = new Vector2((debrisSpawnDirection.x + Random.Range(-1f, 1f)) * dMoveSpeed, (debrisSpawnDirection.y + Random.Range(-1f, 1f)) * dMoveSpeed);
            // Vector2 randomCircle = Random.insideUnitCircle;
            // Vector2 dVelocity = new Vector2(randomCircle.x * dMoveSpeed, randomCircle.y * dMoveSpeed);
            d.Initialize(dMass, dVelocity);
        }

        // Give the player SOMETHING
        SpawnDebrisTowardPlayer();
        Destroy(this.gameObject);
    }