Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (!delay)
        {
            if (spawnedEnemies.Count < maxEnemies)
            {
                delay = true;
                StartCoroutine("Delay");
                GameObject newEnemy = pooler.GetPooledObject(enemyPrefab);
                newEnemy.transform.position = transform.position;
                newEnemy.transform.rotation = transform.rotation;

                spawnedEnemies.Add(newEnemy);

                newEnemy.GetComponentInChildren <turnFollow>().pHolder = assignedPatrol;
                if (GetComponent <Collider2D>() && newEnemy.GetComponent <Collider2D>())
                {
                    Physics2D.IgnoreCollision(GetComponent <Collider2D>(), newEnemy.GetComponent <Collider2D>());
                }
                newEnemy.SetActive(true);
            }
            else
            {
                spawnedEnemies.RemoveAll(item => item == null || !item.activeInHierarchy);
                delay = true;
                StopCoroutine("Delay");
            }
        }
        else
        {
            StartCoroutine("Delay");
        }
    }
Exemple #2
0
    void FireProjectile(GameObject projectile, int pCount)
    {
        for (int i = 0; i < count; ++i)
        {
            //print("FIRING!");
            GameObject newProjectile = pooler.GetPooledObject(bullet);
            newProjectile.transform.position = transform.position;
            newProjectile.transform.rotation = transform.rotation;

            int        middle       = (count - 1) / 2;
            Quaternion trueRotation = Quaternion.AngleAxis(transform.eulerAngles.z + spread * (middle - i) / count + Random.Range(-accuracy, accuracy), Vector3.forward);
            newProjectile.transform.right = trueRotation * Vector3.right;

            newProjectile.SetActive(true);

            if (!parentToObject)
            {
                newProjectile.GetComponent <Rigidbody2D>().velocity = trueRotation * Vector3.right * speed;
            }
            else
            {
                newProjectile.transform.parent = transform;
            }

            if (colorSpread > 0)
            {
                SpriteRenderer bulletSprite = newProjectile.GetComponent <SpriteRenderer>();
                Color          bColor       = bulletSprite.color;
                float          h            = 0;
                float          s            = 0;
                float          v            = 0;
                Color.RGBToHSV(bColor, out h, out s, out v);
                h += Mathf.Clamp(colorSpread * Mathf.Abs(Vector2.Angle(transform.right, trueRotation * Vector2.right)), 0, spread * colorSpread / 2);
                if (h > 1)
                {
                    h -= 1;
                }
                bColor             = Color.HSVToRGB(h, s, v);
                bulletSprite.color = bColor;
            }
        }
    }