コード例 #1
0
    private void Awake()
    {
        planeScript = GetComponent <PlaneShot>();
        shootScript = GetComponent <EnemySimpleShoot>();
        if (planeScript != null)
        {
            scriptAssociado = ScriptAssoc.PlaneShot;
        }
        else if (shootScript != null)
        {
            scriptAssociado = ScriptAssoc.Shoot;
        }
        else if (Application.isPlaying)
        {
            DestroyImmediate(gameObject);
        }

        //Verifica se o atacante está na lista, se não tiver, adiciona
        updateFlexAttackRef();
        if (!flexAttack.attackers.Contains(this))
        {
            flexAttack.attackers.Add(this);
        }
    }
コード例 #2
0
    /// <summary>
    /// Função chamada toda vez que o timer estora. O timer é chamado entre transições de camera
    /// </summary>
    public void finishAnimation()
    {
        //Debug.Log("Transição de estado: " + currentState.ToString());
        //Lógica de mostrar os inimigos. Se ainda tem inimigos que não foram mostrados, vai mover a camera até ele
        if (currentState == GameState.ShowingEnemy)
        {
            //Enquanto ainda tiver atacantes não revelados
            if (showIndex < attackers.Count)
            {
                //Estado de movimento de camera até o inimigo
                currentState = GameState.ShowingMovement;
                //Calcula posição da câmera onde está o inimigo
                Vector3 offset   = new Vector3(attackers[showIndex].cameraOffset.x, attackers[showIndex].cameraOffset.y, 0);
                Vector3 position = attackers[showIndex].transform.position + offset;
                cameraScript.goToLocation(position, cameraMovementTime);
                //Começa o timer
                StartCoroutine(waitTime(cameraMovementTime));
                showIndex++;
            }
            //Se não tem mais quem mostrar, mover a câmera para a posição inicial
            else
            {
                currentState = GameState.Building;
                cameraScript.goToLocation(cameraBuildPosition.position, cameraMovementTime);
            }
        }
        //Se a camera terminou de mover até o inimigo, vai realizar a animação de mostra do inimigo
        else if (currentState == GameState.ShowingMovement)
        {
            currentState = GameState.ShowingEnemy;

            //Indice foi alterado no estado anterior
            attackers[showIndex - 1].playShowAnimation();

            StartCoroutine(waitTime(waitOnEnemyTime));
        }
        else if (currentState == GameState.PlayerAnimation || currentState == GameState.CameraFollowProjectile)
        {
            if (currentEnemy >= enemyOrder.Count)
            {
                EndGame(false);
            }
            else
            {
                currentState = GameState.CameraMovementToEnemy;
                Vector3 offset   = new Vector3(enemyOrder[currentEnemy].cameraOffset.x, enemyOrder[currentEnemy].cameraOffset.y, 0);
                Vector3 position = enemyOrder[currentEnemy].transform.position + offset;
                cameraScript.goToLocation(position, cameraMovementTime);
                StartCoroutine(waitTime(cameraMovementTime));
            }
        }
        else if (currentState == GameState.CameraMovementToEnemy)
        {
            currentState = GameState.EnemyAnimation;
            enemyOrder[currentEnemy].setupAttack();
            float time = enemyOrder[currentEnemy].timeTillAnimation + enemyOrder[currentEnemy].animationTime;
            //Debug.Log("Wait time: " + time);
            StartCoroutine(waitTime(time));
        }
        else if (currentState == GameState.EnemyAnimation)
        {
            currentState = GameState.CameraFollowProjectile;
            nextAttack();
            if (enemyOrder[currentEnemy - 1].scriptAssociado == Attacker.ScriptAssoc.PlaneShot)
            {
                PlaneShot planeScript = enemyOrder[currentEnemy - 1].GetComponent <PlaneShot>();
                cameraScript.goToLocation(planeScript.target, planeScript.getFlyTime() + projectileOvertime);
                StartCoroutine(waitTime(planeScript.getFlyTime() + projectileOvertime));
            }
            else if (enemyOrder[currentEnemy - 1].scriptAssociado == Attacker.ScriptAssoc.Shoot)
            {
                EnemySimpleShoot shootScript    = enemyOrder[currentEnemy - 1].GetComponent <EnemySimpleShoot>();
                Transform        lastProjectile = shootScript.projectile;
                if (lastProjectile != null)
                {
                    cameraScript.followTargetForTime(lastProjectile.transform, shootScript.getFlyTime() + projectileOvertime);
                    StartCoroutine(waitTime(shootScript.getFlyTime() + projectileOvertime));
                }
                else
                {
                    cameraScript.goToLocation(shootScript.target, shootScript.getFlyTime() + projectileOvertime);
                    StartCoroutine(waitTime(shootScript.getFlyTime() + projectileOvertime));
                }
            }
        }
    }