コード例 #1
0
    public void SpawnBoost()
    {
        List <int> freeSpawns = new List <int>();

        for (int i = 0; i < spawnPositions.Length; i++)
        {
            if (spawns[i] == null || spawns[i].gameObject == null)
            {
                freeSpawns.Add(i);
            }
        }

        if (freeSpawns.Count == 0)
        {
            return;
        }

        int spawnPositionIndex     = freeSpawns[Random.Range(0, freeSpawns.Count)];
        PowerupCollectible powerup = powerupOptions[Random.Range(0, powerupOptions.Length)];

        PowerupCollectible instance = GameObject.Instantiate(powerup, spawnPositions[spawnPositionIndex], true);

        instance.transform.localPosition = Vector3.zero;
        spawns[spawnPositionIndex]       = instance;
    }
コード例 #2
0
    public void Think()
    {
        if (enemyCharacter.cooldownRemaining <= 0.2f)
        {
            if (enemyCharacter.canShoot && !shootingThisFrame)
            {
                enemyCharacter.animator.SetTrigger("Throw");
                shootingThisFrame = true;
            }
            if (enemyCharacter.cooldownRemaining <= 0)
            {
                bool    willHit          = (Random.value <= ConfigManager.instance.enemyHitChance);
                Vector3 positionModifier = Vector3.zero;
                float   timeModifier     = 0;
                if (!willHit)
                {
                    //Debug.Log("Will not hit!");
                    positionModifier = Random.value <= 0.5f ? Vector3.right * Random.Range(5f, 10f) : Vector3.right * Random.Range(-5f, -10f);
                    timeModifier     = Random.Range(-0.5f, 1f);
                }
                enemyCharacter.Throw(calculateBestThrowSpeed(enemyCharacter.throwableSpawnPoint.position,
                                                             playerCharacter.aimToPoint.position + positionModifier, 2 + timeModifier));
                shootingThisFrame = false;
            }
        }

        timeUntilNextBoost -= Time.deltaTime;
        if (timeUntilNextBoost <= 0)
        {
            PowerupCollectible powerup = powerupOptions[Random.Range(0, powerupOptions.Length)];
            powerup.powerup.ActivatePowerup(enemyCharacter);
            timeUntilNextBoost = GetTimeUntilNextBoost();
        }
    }