Exemplo n.º 1
0
    /***** SPAWN DUPLICATE FUNCTIONS *****/

    //Spawn a new organism around the current one and return a bool if did so
    private bool SpawnDuplicatedOrganism()
    {
        //Check if there is no object at position before spawing, if yes find a new position
        Vector2 randomPos = new Vector2();
        int     nbTry     = 0;

        while (nbTry < 3) // Arbitrary
        {
            nbTry++;
            randomPos = ComputeRandomSpawnPosAround();
            Collider2D[] hitColliders = TestPosition(randomPos);

            // If touch something doesn't duplicate (avoid organism spawning on top of each other)
            if (hitColliders.Length > 0)
            {
                continue;
            }

            Organism spawnedOrganism = selfOrganism.InstantiateOrganism(randomPos);

            // Copy shield health if organism has shield
            if (spawnedOrganism && spawnedOrganism.GetOrgMutation())
            {
                spawnedOrganism.GetOrgMutation().SetShieldHealth(selfOrganism.GetOrgMutation().GetShieldHealth());
            }

            return(true);
        }
        return(false);
    }
Exemplo n.º 2
0
    private IEnumerator AttackOverTime()
    {
        canAttack = false;

        // Compute dot to apply and round it up
        int damageOverTime = attackTime == 0f ? attackTarget.GetHealth() : (int)((float)attackTarget.GetHealth() / attackTime) + 1;

        // While target alive we apply damage to it
        while (attackTarget)
        {
            targetLastPosition = attackTarget.transform.position;
            attackTarget.DamageOrganism(damageOverTime);

            if (!attackTarget)
            {
                selfOrganism.InstantiateOrganism(targetLastPosition);
            }
            yield return(new WaitForSeconds(attackTarget ? 1f : 0f));
        }

        // Start recall to prevent chain attack
        StartCoroutine(AttackRecall());
    }